Jump to content

posting to self then redirecting?


Rifts

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/225652-posting-to-self-then-redirecting/
Share on other sites

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 />";
}

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 />";
   }
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.