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
cURL proxy
Okay here is the thing... i know how to add proxys
Code: curl_setopt($ch, CURLOPT_PROXYTYPE,
PHP time (deadline within one week)
I have a column ['projdue'], which stores the deadline for a project.
I have PHP code and <
SAP BCS. BPS
Hi all,
I am seeking reading note on the following in BW
BCS, BPS
ADVANCE
IF STATEMENT HELP
Hi
i have created a calendar from a table:
Code: Calendar: October 2009
<table w
MYSQL INSERT ID NOT WORKING
Code: $id = mysql_insert_id();
header("Location: ./?view=$id");
Why $id pulling blan
foreach iterator
Hi Guys
Does the foreach loop have an inbuilt iterator ?
how to load a Sys file with system load and call images?
normally you need register the module as a service with CreateService, and start the service
help retrieiving results and doing pagination
Having some trouble trying to get the results to show on more than just one page.
What is ha
Splitting Attributes
SQL> SELECT I_NAME, substr(I_NAME,1,instr(I_NAME,'O')) "First part",
substr(I_NAME, IN
Database/Table Collation
What is the Database, and table collations used for? i don't understand what there used for since co