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
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
DOMDocument
Hello All,
I need to take an XML document, modify some of the nodes in it and then perform a
Getting number of affected rows in SQLPLUS..
Hi everyone,
I have a shell script where i am invoking sqlplus, running a query and saving t
Date Format
Hi there,
I have a date format like this right now:
Sat, 17 Oct 2009 17:04:00
I ne
Error: SQL Syntax; Line 1
Code:
<?php require "global_settings.php"; ?>
<title&g
foreach help.
Hello all,
First time I'm attempting to use a foreach statement and was just wondering if my
login and redirect
hello! can someone help me.. can you give me an idea.. I want to make a login page and redirects it
Better Method of a Member Cloud
I assume most people know how tag clouds work, where the tags most used are bigger and the least use
urldecode question
How would I format this line of code properly?
<?php echo urldecode($_GET['Title']); ?
How to sum these output values
Hi
I need sum the month totals
SELECT region_name, area_name
,SUM (CASE WHEN S
user administration
Dear @all,
what I have to do to set the user defaults for new users. At the moment I woul