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
PHP Surveys
I really would like some advice.
If you have a client come to you asking for a survey to be d
Agency Business Process
Hi,
I don’t understand the process of the agency business in SAP.
In my
mr8m - reverse document
Friends,
I'm trying to reverse a document held by MIRO, but it reports the message balan
Line break?
Hi, I'm new to the forum and new to php. I'm not sure if I'm using the correct terminology so here i
Format timestamp from mysql
When I tried this:
Code: date("m/d/Y H:i A", $row['timestamp'])
I got 12/31/1969 18:
PHP, Arrays & A Lot Of Confusion
I've been doing basic PHP work on sites for a few years now, but I've never been tempted to learn ho
TemplatePower & AJAX
Hi all,
I'm currently implementing some AJAX features in my PHP-framework (which is b
Pagination
Okay here is the page in question: http://blenderteachings.000a.biz/tutorials.hamishhill.php
Simple AND question
Hello,
I've got following code:
Code: if(strpos($row[13],"http://")
ereg_replace()
Basically what i need to do is
$title = "This Suck's"
$striped = ereg_repl