Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Launching a new page

Status
Not open for further replies.

smiffy47

Programmer
Apr 6, 2004
95
GB
With the help of an introductory php tutorial I've just started to put some php into my sites.
I've cracked how to compare the value of strings and get a comparison to operate, eg
<?php if ($password = $yourpassword){
echo 'OK';
}
else {
echo 'Wrong Password';
}
?>

Now, instead of "echo 'Wrong Password';" I want the result to be the launch of a different web-page. What code is required? Where do I find out more? The tutorials I've explored all seem to stop just when things are getting interesting!

Life...It's difficult not to take it personally.
 
With PHP, if you're comparing 2 things in an if statement you need TWO equal signs: ==, not one like you have in your example.

Then you need to look up the code to redirect to a different page, but make sure you haven't printed anything to the page before the redirection or PHP will issue an error message.

Lee
 
Lee is perfectly correct. Your example will always evaluate as true, since you're assigning $yourpassword variable to $password variable. That will always happen, so it will always be true.

As regards to your redirection question, you should use the header() function like this:
Code:
header ("Location: /path/to/page.php");
Since this function sends headers (something that needs to happen before any output, Lee is again correct in telling you that you should not have any html, white-space or echo/print commands before header is issued.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top