Jump to content

weird setcookie problem


Bramme

Recommended Posts

Okay, so I'm working on a little project, and I've got a little loginbox, it has a checkbox, just like vbulletin, to keep you logged in(set a cookie) or just use a $_SESSION...

So here's how my login script looks:

 

<?php
// Log in
$loginname = isset($_POST['usname']) ? $_POST['usname'] : "";
$loginpass = isset($_POST['passw']) ? $_POST['passw'] : "";

$loginpass = md5($loginpass);

$remember = isset($_POST['remember']);

if(!empty($loginname) && !empty($loginpass)) {
$c = mysql_num_rows(mysql_query("SELECT * FROM accounts WHERE name = '$loginname' AND password = '$loginpass'"));
if($c > 0) {
	if($remember == TRUE) {
		setcookie("usname", $loginname, time()+(7*86400));
		setcookie("pass", $loginpass, time()+(7*86400));
	} else {			
		$_SESSION['loggedin'] = $loginname;
	}

}
}
header("Location: /play/game/");
?>

Now, I soon noticed that i wasn't logging in when using cookies (session works fine), so I decided to echo the cookies in my index.php

// Log in check: 
if(isset($_SESSION['loggedin']) || isset($_COOKIE['usname'])) {
... //i've tried combinations of isset and !empty, no difference
}

// testing if they are set in index.php
echo 'usname: '.@$_COOKIE['usname'].'<br />';
echo 'pass: '.@$_COOKIE['pass'].'<br />';
echo 'session: '.@$_SESSION['loggedin'].'<br />';

and the cookies all return zip... So i thought there must be something wrong with the way i'm setting these cookies... However, when i had a look at my cookies (with mozilla firefox) i soon saw that they were perfectly set... I've got a cookie usname, with the username, and a cookie pass, but the website doesn't recognize them for some reason... other way around, when I log out

<?php
// Logout
setcookie("usname","");
setcookie("pass","");
session_destroy();
header("Location: /read/home/");
?>

the cookies stay, right were they are...

 

I haven't got a clue what's going on... I first thought it had something to do with the way I included my login page, but I've tried different things and none work...

Link to comment
https://forums.phpfreaks.com/topic/51969-weird-setcookie-problem/
Share on other sites

nope, doesn't work either, they just remain there... i'll upload all the files used, so if anyone would have some spare time, they could have a look at it...

 

edit: http://bramme.net/cosmosw/ those are the files

 

you can see it live here: http://bramme.net/cosmoswars/

the username and password are both "demo"

<?php
// Logout
setcookie("usname","",time()-3600);
setcookie("pass","",time()-3600);
-------------------------------------
//////// Check here do you found set cokkies here
echo "<pre>";
print_r($_COKKIE);
exit;
-------------------------------------
session_destroy();
header("Location: /read/home/");
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.