Jump to content

Cookie possibly header question


The Midnighter

Recommended Posts

I've got some code. (duh)

 

It keeps telling me I'm trying to send headers twice, does anyone have any reason why it might say that? The two lines in question are as follows,

 

Warning: Cannot modify header information - headers already sent by (output started at /hdd/2/home/com/info.mooseheadbeer.com/password_protect.php3:80) in /hdd/2/home/com/info.mooseheadbeer.com/password_protect.php3 on line 79

Thats' the error, the two lines are:

 

			setcookie("verify", md5($login.'%'.$pass), $timeout, '/');
		echo "Password correct.";

Link to comment
https://forums.phpfreaks.com/topic/139292-cookie-possibly-header-question/
Share on other sites

 

 

Are you actually still using php3?

 

It is most likely that the code is in a loop or in an include file that is being included more than once. What is the rest of the code? Just posting the two lines of code out of context does not give anyone enough information to help with the problem.

You were right on Scott, when I removed the next line (the echo) the error went away.

 

now I have a cookie question, I'm setting my cookie with this:

 

 if (isset($_POST['pass'])) 
{

	$sql = "SELECT * FROM Portal_administrators WHERE admin_name='" . $name . "' AND password='" . $pass . "';";

	$furesult = mysql_query($sql);
	$valid = (mysql_fetch_row($furesult) != false);

	if (!$valid) 
	{
		showLoginPasswordProtect("Incorrect password.");
	}
	else
	{
		setcookie("verify", md5($login.'%'.$pass), $timeout, '/');
	}
}

 

And it validates like this:

 

else
{
	if (!isset($_COOKIE['verify'])) {
	showLoginPasswordProtect("");
}
  
    // check if cookie is good
  $found = false;
  foreach($LOGIN_INFORMATION as $key=>$val) {
    $lp = ($key) .'%'.$val;
    if ($_COOKIE['verify'] == md5($lp)) {
      $found = true;
      // prolong timeout
      if (TIMEOUT_CHECK_ACTIVITY) {
        setcookie("verify", md5($lp), $timeout, '/');
      }
      break;
    }
  }
  if (!$found) {
    showLoginPasswordProtect("");
  }
}

 

It seems like the cookie isnt' storing properly, what did I do wrong? :(

i don't know why it would be working but what PFMaBiSmAd said made some sense are you including the file?

and is it possible for the file to be included more than once?

or is that code that sets the cookie in some kind of loop?

both of those would explain why you got the first error which seems very strange.

 

Scott.

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.