Hi, I am trying to make a very simple login where someone enters a username and pass word and as soon as they enter the correct uname and password fo it to redirect them to www.yahoo.com here is the code i am using <hmtl> <head /> <body> <form action="index.php" method=POST> Username1: <input type=text name=user><br /><br /> Password: <input type=password name=pass><br /> <input type=submit value="Go!"><p> </form> <?php $user=$_POST['user']; $pass=$_POST['pass']; if(($user=="John")&&($pass=="Smith")) header("Location: http://www.yahoo.com"); else echo "Access Denied!"; ?> </body> </html> Thanks in advanced
All redirects have to be done before any of hte HTML is parsed. Put your PHP at the start of the code (above the HTML) and then assign 'access denied' to a variable and echo the variable where you want it!
<?php $user=$_POST['user']; $pass=$_POST['pass']; if($user=="John" && $pass=="Smith") { header("Location: http://www.yahoo.com"); }else{ echo "Access Denied!"; } ?> <html> <body> <form action="index.php" method="post"> Username1: <input type="text" name="user"><br /><br /> Password: <input type="password" name="pass"><br /> <input type="submit" value="Go!"> </form> </body> </html> Code (markup): Try this..
In your script, you haven't even used the { and } for the if statement and the else statement. So your script isn't processing what you want it to do
projectWORD is write. I think this has been explained pretty well, you cannot send headers when content has already been sent. If you want to check to see if the username/password were valid users, that might be more difficult.
true, i just find it cleaner to use { and } in my if statements. i did kinda skim read the provided code for any kind of syntax error, and so it was my fault for not actually checking for content sent to the page prior to the header tag. :< I'll remember to read all of the code next time ^^. I've learnt my lesson