I'm trying to create a login script but I can't figure out how to pull the data out of a $_COOKIE and how cookies work with $_SESSION.
Basically I have this
//pull data from database
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
//store in the database strip for sql injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
//query database, check to see if username and password exist there / encrypt
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password=SHA('$mypassword')";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
//if it exists, register the session with the username nad password, then set a cookie
if($count==1)
{
$_SESSION("myusername");
$_SESSION("mypassword");
setcookie("username","$myusername",0);
header("location:cookietest.php");
}
else
{
echo "Wrong Username or Password";
}
Then inside my cookietest.php..
if(isset($_SESSION['username']))
echo "session varible set and ";
else
echo "session varibale not set and ";
if(isset($_COOKIE['username']))
echo "cookie is set";
else
echo "cookie is not set";
Even thogh I can see int he browser that the cookie was created I get "session varible not set and cookie is not set"