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
Progress bar tracking file downloads
Hey guys, was wondering if there was a way to track how far a file has been downloaded. I know there
PHP File Upload Problem
Hi, I have written a very simple file upload script but it fails for reasons I can't explain. Hope
Include with Parameters
In a particular page I would like to include a file that requires $_GET parameters.
when I go
HTML Form Server Side Validation
Hi, Im new here, im currently doing a website for a friend, and I have designed using snippets from
Hotlinking Picasa as the image folder of a website
Hi there PHP freaks, I would like to create a private album in Picasa to use it as the image folder
SCRIPT ERROR
Here is the CONTACT FORM I made for our website:
<form id="form1" name="
Help with setcookie()
Merry Xmas to those on this foruum
Older guy here with some experience but not allot so please be
PayPal Redirect Issue
When I have my paypal button set so that is redirects to http://empiremarketing.ca/order.php,it work
Namespace Problem
I'm having problem with a section of code with a variable namespace.
This code works fine:
Php mysql - select?
Hi i have this code:
Code: $iteminfo = mysql_query("SELECT desc FROM wc_items WHERE itemid =