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 help PLEASE
ok i have this warning showing up
Warning: in_array() [function.in-array]: Wrong datatype for
Concatenate two strings ???
I have string one $string1 and another $string2.
How to concatenate (add) both of them $str
Code Review - SQL and Insertion Attacks (Warning: Not for Newbs)
Hey guys,
Its been a while, I know. Use to love coming here to answer peoples questions, but
how to make database item unique
Hey guys,
is it possible to do this:
I have the database item $title being pulled for
Parse Error Help
Hello, I got the parse error "Parse error: syntax error, unexpected ',' in register.php on line
PHP form authentication
Hi guys,
what am trying to achieve is this: Whenever a user tries to login to my website, an
duplicate record notification
In my database, after insertion of records, I want to know if the record inserted is duplicate or no
Pop-up Banner
Hello Friends,I need to use banner in our client site.Example: www.example.com if i enter this site
timed header image rotation
I have a joomla site and I was trying to setup a rotating image based on timing NOT just refreshing
Change snippet to use CURDATE
I am using time() in the snippet below, I would like to use CURDATE() and have the database setup fo