setcookie and isset($_COOKIE(name)) seem very finnicky.
Posted on
16th Feb 2014 07:03 pm by
admin
I'm currently playing around with a user system with login and registration. I'm trying to use cookies to log the user in but the cookie either doesn't set or it sets after I travel through a few pages. Also, when I use isset($_COOKIE(name)) it sometimes doesn't return that it is set even though it is.
login.php (the username and password request page which I am currently using to display if a cookie is set)
Code: <?php
Did you know?Explore Trending and Topic pages for more stories like this.
if (isset($_COOKIE["grocerycookie"]))
{
$username = $_COOKIE["grocerycookie"];
echo "You are logged in, <b>$username</b><br />";
}
else
{
echo "You have not been logged in.";
}
?>
login2.php (sets the cookie)
Code: <?php
mysql_connect("*", "*", "*") or die(mysql_error());
mysql_select_db("*") or die(mysql_error());
$username = strtolower($_POST['username']);
$password = $_POST['password'];
$data = mysql_query("SELECT * FROM * WHERE username='$username'") or die(mysql_error());
while($info = mysql_fetch_array($data))
{
if ($password == $info['password'])
{
setcookie("grocerycookie", $username, time()+3600);
}
}
Am I setting the cookie wrong or checking for it wrong?
No comments posted yet
Your Answer:
Login to answer
112
47
Other forums
Need Successful Return
Hello I am currently working a form here, and I have everything figured out except when I click the
undefined offset help
Hi All,
I kept getting undefined offset PHP notice for a simple for loop. For eg
$va = arr
Mail Script Problems
I have created a PHP mail script. I am having a problem though. In $body i am trying to put two va
Need help to identify this error please
:confused:Can anyone help me tell what this error message means? Maybe tell me where to look to fix
values in array being escaped
I would like to submit some values - back to the same form for checking before processing...
PHP Search Issue
Hi, I am using the following code to search and return flights from a database. The user searches by
mod_rewrite.c on windows ??
why it's not working on windows while it's working on other hosts???
this is the code i got
Search function
I am looking for some guidance from the experts.
I am trying to create a search function. It
Images in email problem
I found this script for sending emails, it works but if the email has <img src="image.jp
Check Date/Time in PHP
What I need the code to check is that $reQuest is 24 hours in the past then return a time based on h