Jump to content

PHP Cookies Help


danieljgraham

Recommended Posts

Im trying to use the following code;

 

if($login_Remember) { /* Check if Remember Me was set */
      setcookie('login_ID', $row['ID'], time()+3600 * 24 * 30);
      setcookie('login_Name', $row['Name'], time()+3600 * 24 * 30);
      setcookie('login_Access', $row['Value'], time()+3600 * 24 * 30);
}
header("Location: index.php");

 

When i try to use it, the only cookie thats registered is the bottom on "login_Access". None of the others are. I have tried everything but nothings working.

 

I dont get any error messages.

 

Using PHP v5.3.3 on IIS

 

Please help.

 

Thanks

 

[attachment deleted by admin]

Link to comment
Share on other sites

Thank you for your help, heres what i came up with, and appears to be really secure.

 

if($login_Remember) { /* Check if Remember Me was set */
         $sql = "UPDATE Users SET Session = '$session_id' WHERE id = " . $row['ID'];
         mysql_query($sql);
         setcookie('PDMS_SESSION', $session_id, time()+3600 * 24 * 30);
}

 

Then on every page i do a Session check, if that ok then it just returns true. Otherwise it'll check the cookie and and do an SQL query for that cookie

 

Public function doLoginCheck () {
         if(isset($_SESSION['login_ID'])) {
                  return true;
         }
         if(isset($_COOKIE['PDMS_SESSION'])) {
                  $query   = sprintf("SELECT users.* , user_groups.Value FROM users LEFT JOIN user_groups ON (users.Access = user_groups.ID) WHERE users.Session = '%s' LIMIT 0,1", $_COOKIE['PDMS_SESSION']);
                  $result  = mysql_query($query) or die('Error, Cookie check failed');
                  $row     = mysql_fetch_array($result, MYSQL_ASSOC);
                  $_SESSION['login_ID'] 	= $row['ID'];
                  $_SESSION['login_Name'] = $row['Name'];
                  $_SESSION['login_Access'] = $row['Value'];	
                  return true;
         }
         header("Location: login.php");
}

 

Seems to do the trick.

 

Thanks for your help.

 

Dan

Link to comment
Share on other sites

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.