xuniter Posted January 22, 2011 Share Posted January 22, 2011 i have the following code which should redirect the user to the index.php page, but instead it shows error 404 page not found....Please if anyone see the problem help me login.php <?php session_start(); ?> <html> <head> <title>Basic CMS | Admin area Login</title> </head> <body> <?php if (isset($_SESSION['user'])) { header("Location: index.php"); } else { ?> <form action="dologin.php method="post"> <table> <tr> <td><span>Username:</span></td> <td><input type="text" name="username" /></td> </tr> <tr> <td><span>Password:</span></td> <td><input type="password" name="password" /></td> </tr> <tr> <td colspan="2" align="right"><input type="submit" name="login" value="Login"/></td> </tr> </table> </form> <?php } ?> </body> </html> dologin.php <?php session_start(); ?> <html> <head> <title>Basic CMS | Admin area Login</title> </head> <body> <?php if (isset($_SESSION['user'])) { header("Location: index.php"); } else { ?> <form action="dologin.php method="post"> <table> <tr> <td><span>Username:</span></td> <td><input type="text" name="username" /></td> </tr> <tr> <td><span>Password:</span></td> <td><input type="password" name="password" /></td> </tr> <tr> <td colspan="2" align="right"><input type="submit" name="login" value="Login"/></td> </tr> </table> </form> <?php } ?> </body> </html> index.php <?php session_start(); if(isset($_SESSION['user'])) { ?> <html> <head> <title>Basic CMS | Admin area</title> </head> <body> </body> </html> <?php } else { header("Location: login.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/225301-cant-find-the-page/ Share on other sites More sharing options...
trq Posted January 22, 2011 Share Posted January 22, 2011 According to the HTTP specs, the Location header should be a complete uri, not just a filename (of course most browser seem to work ok without, but it's best practice). Quote Link to comment https://forums.phpfreaks.com/topic/225301-cant-find-the-page/#findComment-1163551 Share on other sites More sharing options...
hvandracas Posted January 22, 2011 Share Posted January 22, 2011 Well, if the page in the header is in the same folder as the page you're are being redirected from than it should work, however if it's not, than you should either use full path (http://...) or use other marks to mark the target file (for example ../page.php or folder/files/index.php). Quote Link to comment https://forums.phpfreaks.com/topic/225301-cant-find-the-page/#findComment-1163557 Share on other sites More sharing options...
trq Posted January 22, 2011 Share Posted January 22, 2011 or use other marks to mark the target file (for example ../page.php or folder/files/index.php According to the HTTP specs, the Location header should be a complete uri, not just a file name or path to a file. Quote Link to comment https://forums.phpfreaks.com/topic/225301-cant-find-the-page/#findComment-1163569 Share on other sites More sharing options...
Fergal Andrews Posted January 22, 2011 Share Posted January 22, 2011 Hi xuniter, The problem is with the form action. You're missing an end quote: <form action="dologin.php method="post"> should be <form action="dologin.php" method="post"> Also, headers need to be sent before anything is output to the page. It is best to move your php code containing the header command to the top of the page before <html>, etc. There's no need to use an else command. If the condition is not met then the code will just continue. If it is met then the header will redirect to the new page. Cheers, Fergal <?php if (isset($_SESSION['user'])) { header("Location: index.php"); } ?> <html> <head> <title>Basic CMS | Admin area Login</title> Quote Link to comment https://forums.phpfreaks.com/topic/225301-cant-find-the-page/#findComment-1163590 Share on other sites More sharing options...
xuniter Posted January 22, 2011 Author Share Posted January 22, 2011 WOW!!! Thank you so much, i was sitting all night trying to find the problem, and didn't saw that end tag! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/225301-cant-find-the-page/#findComment-1163628 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.