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
Inserting a variable in a link
I have this code that I want to insert for my own variable but I have no idea how. This is what I wa
Unidentified index error in a simple form
I have been trying to make an HTML form that is handled by a PHP script. So far my attempts to get i
Join Query Help
Hi all,
I am having problems with the below code, which we shall call 'my first join query'!
Auto fill in input value based on User_ID
Hello,
I'm looking form some input on the following problem.
User loads page ->
Option box to change variable
Hello, i need help by making a script!
I need to write a file with option box, so a dropdown
Preserving user-entered linebreaks
Hi, I'm building a web 2.0 thingy from scratch and I wanna display text which users input. It's all
Procedure with variable number of columns
Hi, I have a procedure that looks like this:
PROCEDURE PROC(p_cursor OUT sys_refcurso
Alterar a hora do servidor
Se alguém souber, ajude-me a adicionar 6 horas, obrigado
<tr>
&
media recovery
Hi,
i startup the database i got the error
SQL> startup
ORACLE instance started.
filesize() returns 0
I have a socket program that runs in an infinite loop, listening for connections, in this socket I h