Jump to content

Recommended Posts

Code:

<?
include 'db.php';
if (isset($_POST['user'])){
$name = htmlentities($_POST['user']);
$pass = md5($_POST['pass']);
$result = mysql_query("SELECT * FROM `Players` WHERE `name` = '$name' AND `password` = '$pass'");
$num = mysql_num_rows($result);
if ($num == 1){
$row = mysql_fetch_array($result);
$key = $row['s_key'];
setcookie("login", $key, time()+(60*60*24*365));
$s = 1;
}else{
$fail = "<br><b><i><font color=\"red\">FISSION MAILED: Try Again</font></i></b>";
}
}else{
$nl = 1;
}
?>

 

Problem

I try to set the cookie, and I know it sets, as it lets me onto my page which has a "if(isset(....."

 

Trouble is, Im echoing $key and $_COOKIE["login"] and printing all my cookies. I see $key (which is good).

I DONT see $_COOKIE["login"] which should be the same as $key and i dont see the cookie appear in the printing of all my cookies.

 

???

 

Link to comment
https://forums.phpfreaks.com/topic/104887-solved-sessions/
Share on other sites

Back to your first post, since you did not show where you were trying to display the cookie and expected $_COOKIE["login"] to be set, I will guess it was on the page where you were setting the cookie. If so, from the manual -

 

Cookies will not become visible until the next loading of a page that the cookie should be visible for

 

The $_COOKIE array is set when a page is requested and the browser sends the cookies to the server. Until you refresh a page or goto a different page $_COOKIE["login"] won't exist in the $_COOKIE array.

 

If you are still not receiving the cookie, it is probably due to the path or host part of the domain changing or you are not actually setting the cookie due to a header problem.

Link to comment
https://forums.phpfreaks.com/topic/104887-solved-sessions/#findComment-537222
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.