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 Like 47 Dislike
Previous forums Next forums
Other forums

Parse XML
Good day,

I use oempro software and try to parse XMLReturn but it's not working for me, simpl

reating a background image
I am building a site in drupal and have a php form in it, due to certain annoyances with module buil

Multiple websites question.
Hi, does php have any functionality that enables a programmer to extract information from a website

How would I do "Users not logged in since *** delete them"
I know how I would set this up, and delete the user roughly.
I'll create a table called "Use

Ajax not working on IE 6 for Windows CE
I've created a webpage which uses the classis Ajax in following format:view plaincopy to clipboardpr

Alterar a hora do servidor
Se alguém souber, ajude-me a adicionar 6 horas, obrigado
<tr>
&

Do While statement
hi guys,

This may sound trivial but im new to php and as part of an assignmenti have to const

$action = "insert"; //$action = $_GET['action'];
$action = "insert";
//$action = $_GET['action'];

why is this invalid type? I am

selectbox+database connection retrive problem
Code: [Select]
<tr>
<th align="left" scope="c

Cursor statement failed with errors
Following statement failed with the errors.

cursor proj_cursor1 is (select projectID from

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash