Rifts Posted January 25, 2011 Share Posted January 25, 2011 Is there anyway to do this: my form is posting to self, then checking login creds. if they are incorrect it spits out "invaild bla bla" but if they are correct send them to a different page? here is the short version of what I have. if(isset($_POST['submit'])) { //check inputs vs db if ($check) { header("Location: http://". $_SERVER['SERVER_NAME']."/include/process_renew.php"); } else { echo "<font color='red'>Username or Password did not match.</font> <br /><br />"; } } } I tested it using echo first and it worked fine then replaced the echo with header and now when I submit it just refreshes the page. is this not possible? Quote Link to comment https://forums.phpfreaks.com/topic/225652-posting-to-self-then-redirecting/ Share on other sites More sharing options...
Pikachu2000 Posted January 25, 2011 Share Posted January 25, 2011 If the echo is what you expect it to be but the header redirect fails, the headers may have already been sent. if ($check) { if( !headers_sent() ) { header("Location: http://". $_SERVER['SERVER_NAME']."/include/process_renew.php"); } else { echo 'Headers already sent. Can\'t redirect.'; } } else { echo "<font color='red'>Username or Password did not match.</font> <br /><br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/225652-posting-to-self-then-redirecting/#findComment-1165102 Share on other sites More sharing options...
AbraCadaver Posted January 25, 2011 Share Posted January 25, 2011 You should use exit; after a redirect. Also, there is an unmatched curly brace (count them). Quote Link to comment https://forums.phpfreaks.com/topic/225652-posting-to-self-then-redirecting/#findComment-1165109 Share on other sites More sharing options...
_DarkLink_ Posted January 25, 2011 Share Posted January 25, 2011 You may also use a meta-refresh. if(isset($_POST['submit'])) { //check inputs vs db if ($check) { echo "<meta http-equiv=\"refresh\" content=\"0;url=". $_SERVER['SERVER_NAME']."/include/process_renew.php\">"; } else { echo "<font color='red'>Username or Password did not match.</font> <br /><br />"; } } Quote Link to comment https://forums.phpfreaks.com/topic/225652-posting-to-self-then-redirecting/#findComment-1165223 Share on other sites More sharing options...
BlueSkyIS Posted January 25, 2011 Share Posted January 25, 2011 i would not rely on meta refresh, as it relies on the visiting application (which is sometimes but not always a web browser) to redirect the user to a new url. If SEO is a consideration, meta refresh can MESS YOU UP. Quote Link to comment https://forums.phpfreaks.com/topic/225652-posting-to-self-then-redirecting/#findComment-1165226 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.