Jump to content

PHP Cookies Help


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.




[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'];
         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.



Link to comment
Share on other sites


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.