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
How do I give a developer access to a specific directory and nothing else?
I want to give a develop access to a specific directory and nothing else
I can give them an F
Stats of viewers
Hello. I have a website in php and people can login. I want to make an admin control panel where u c
New Search Engine problem
Hey everyone,
I have a ZIP Code Radius search engine already functional. it displays all of t
Calander layout
Hi i know this sounds like a simple question but i cant find the answer to it anywhere i have added
File upload issues
Hi Guys,
Can anyone see any issues with this code:
Code: [Select]$setImage= 'productimages
reorder sql query
ok so i have this very simple code:
Code: $query = "SELECT search_keywords, COUNT(search_key
Sequencing or queuing parallel process
Scenario is as follows
There is one parent process say P1 and 4 child processes say A B C D
Help with ORDER BY
Hello. I would like to order by ascending States, then Cities, then Gyms in the following code, but
Quick Question about echo value
Hey guys, I'm trying to get something to show differently in one of my scripts. I'm trying to make
generating all possible random letters
hi'
how can i randomize the letters a,b,c,d,e all possible ways, and i want to print the res