Jump to content

Header not redirecting


kyles0623

Recommended Posts

I have this:

 

function login_check(){

echo" WOOT!";

if(isset($_COOKIE['ID_my_site'])):
echo "hello";
$username = $_COOKIE['ID_my_site'];
echo" WOOT!";
$pass = $_COOKIE['KEY_my_site'];
	echo" WOOT!";
$sql = "SELECT * FROM users WHERE username = '$username' ";
$res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($res)){
		echo" here!";

	if($pass != $row['password']):
		header("Location:login.php");
	else:
		header("Location:login.php");
	endif;
	}
else:
header("Location:login.php");
echo "hello";
endif;

}

 

 

If you notice in the else statement at the end there is a header redirect. It doesnt work. It does work though if i make it the first thing in the function. Also, the function echo's out the hello in the else statement at the end.  This function is called before the head tag. Any ideas?

Link to comment
Share on other sites

You cannot output ANYTHING (including a html doctype tag or any other character) before you use a php header() statement as that prevents the header() from working.

 

If you were developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini, php will help you by reporting and displaying all the errors it detects.

Link to comment
Share on other sites

Could you not put ob_start(); at the begining of the script and ob_end_flush(); at the end?

To could, or you could just do it correctly in the first place! :P

 

Yer ok ok lol. I just thought aswell. If you're gonna redirect to another page. Why echo on that page?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.