tags:

views:

350

answers:

2

Hello,

I want my php to open a new html page.

I have a html page, where a member can login by typing her username and password and then click on button.

if the username password is correct, i want my php to open a different html page in the same window.

how can i do this??

Zeeshan

+6  A: 

Try using the header function.

header("Location: $url");
Keith Maurino
Ensure that it comes before any other output, mind you.
Williham Totland
Specifically, output that header if the login succeeds.
Dave
Note that the `Location` header must be an absolute url. So `header("Location: http://www.example.com/user/home.php")`
Blixt
Darn it... that is supposed to be including the `http://` protocol and the `www.` subdomain.
Blixt
nope, it doesn't./example.php is enough.
Michal M
Don't rely on it. Some browsers implement it, but here's the actual standard definition: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30
Blixt
+1  A: 

Or, the 'techless' solution:

<html>
<head>
    <title>Redirecting...</title>
    <meta http-equiv="refresh" content="0;URL=newpage.php">
</head>
<body>
    You are being automatically redirected to a new location.<br />
    If your browser does not redirect you in few seconds, or you do
    not wish to wait, <a href="newpage.php">click here</a>. 
</body>
</html>

See Here.

DaNieL
Ideally, output both at the same time. If the browser for some reason ignores the `Location` header, it will still get this page.
Blixt
Yes, using the location and the meta both will give the best affidability: just last years some browsers dont follow the location, and some other the meta (i remember that safari, for example, didnt take correctly the meta way if the tag was written capitalized)
DaNieL