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!

redirect 1

Status
Not open for further replies.

dugen

Programmer
Jun 16, 2003
59
US
This is a simple unsecure username and password procedure i am using. The redirect works for the first if, but the next if statement does not work. Can i only have one redirect in this code?


<html>
<head>
<title>Displaying the Inputted Information</title>
</head>

<body>
<?php

// obtaining the information from the form and displaying it


if (($txt_username == building9) && ($txt_password == li))
{

('Location: exit();


}
elseif (($txt_username != building9) && ($txt_password != li))
{

header('Location: exit();

}



elseif (($txt_username == building8) && ($txt_password == fn))
{

('Location: exit();


}
else (($txt_username != building8) && ($txt_password != fn))
{

header('Location: exit();

}

?>

</body>
</html>
 
What is location only in parenthesis doing there? Isn't that missing a header call? When we're at headers, you can have as many as you want in different blocks in your code, as long as you know that as soon as your code hits one, it will redirect to the next page and stop executing the code on the current.

Headers are somethings that are sent before the output is started. That means that all the header calls must be made before any output is made to the browser. This includes:

a) any html code outsite php tags (this is what you have);
b) any whitespace or carriage returns before php tags (this is what you could also have);
c) any print or echo statement;
d) any error that outputs to the browser.

Make sure you don't have any of that before the header call and you'll be ok.
 
Thanks alot Vragabond!!

I was having alot of trouble with this because the code was working fine on my test server, and when I uploaded it to another server it was not working.

I took out the HTML before and after the php tags and it works percect now on both host servers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top