I know that there are some funky things with cookies and that you have to set them before the header information is sent. How do you know when the header info has been sent? I just know that cookies need to be set before the HTML <HEAD> tags and there might be problems if they are combined with a header function.

The script below was taken from: http://robouk.mchost.com/tuts/tutorial.php?tutorial=login3 For the life of me, I can't get it to set the cookie. I tried replacing the part where it sets the cookie with a header redirect and it doesn't work either. Does this mean that the header information has already been sent?

<?php
include("common.php");

if(!($link_id = mysql_connect($Host, $User, $Pass))) die(mysql_error());
mysql_select_db($D😎;

$sql = "SELECT ID FROM " . $Table . " WHERE Name='" . addslashes($POST['Name']) . "' AND Password='" . md5($POST['Password']) . "' LIMIT 1";
if(!($result = mysql_query($sql))) die(mysql_error());

if(mysql_num_rows($result) == 1) {
setcookie($_POST['Name'], "LoggedIn", time()+(3600 * 24));
echo "Continue to the <a href=members.php>Members</a> page.";
} else {
echo "Login failure";
}
?>

    Headers can be strange - make sure there is no white space - empty lines or just spaces in the "common.php" file and try taking out the lines in the code given below until the setcookie line...

    May help...

      I forgot how much cutting and pasting can mess with code. I also had to change:

      setcookie($_POST['Name'], "LoggedIn", time()+(3600 * 24));

      to

      setcookie("LoggedIn",$_POST['Name'], time()+(3600 * 24));

      Thanks for your help

        Write a Reply...