Reputation: 35
My login does not seem to be creating a cookie. The form gets all the way to the cookie creation portion of the script and even echos that a cookie was made but it does not actually create one.
Here is the cookie portion of my code:
if (!$error) {
if (isset($_POST['rememberme'])) {
setcookie('guruemail', $loginemail, time() + 86400 * 365, '/', NULL);
setcookie('gurupassword', md5($loginpassword), time() + 86400 * 365, '/', NULL);
echo "Long-term cookie made";
} else {
setcookie('guruemail', $loginemail, false, '/', NULL);
setcookie('gurupassword', md5($loginpassword), false, '/', NULL);
echo "Short-term cookie made";
}
}
The login can be visited at http://protein.guru/signin.phtml
The cookie test can be viewed at: http://protein.guru/testcookie.php
Here is the cookietest code:
<?php
echo "Value is: " . $_COOKIE[$guruemail];
echo "Value is: " . $_COOKIE[$gurupassword];
?>
For the sign-in:
I am using the email: [email protected]
Password is: meatloaf
Note:Possible newbie mistake? -- I do not have a session_start(); anywhere in either code. Not sure if I would need that for a straight cookie login.
Any feedback would be appreciated. Thanks everyone.
Upvotes: 2
Views: 125
Reputation: 6896
You'll need quotes around the cookie variable
<?php
echo "Value is: " . $_COOKIE['guruemail'];
echo "Value is: " . $_COOKIE['gurupassword'];
?>
Actually it would be much more secure to use $_SESSION
instead for users login as users can manually set $_COOKIE
.
More details at the following answer: Making login more secure
Upvotes: 1
Reputation: 1634
As mentioned in the comments: Access the $_COOKIE arrays with strings, instead of a variables.
<?php
echo "Value is: " . $_COOKIE['guruemail'];
echo "Value is: " . $_COOKIE['gurupassword'];
?>
Upvotes: 4