Page 1 of 1

Cookies and Macs

Posted: Sun Nov 23, 2003 5:07 pm
by wtso
I'm trying to set a cookie for a session with some PHP code. It works just fine on PC machines, but it's not working on a Mac that is trying to get in. With regards to coding, is there anything different for a Mac as opposed to a PC?

Here's the code:

<?php
if (($username=="username") && ($password="password"))
{
setcookie("login", "yes", 6000);
print "You are logged in.";
}
else
{
print "Failed";
}
?>

Posted: Sun Nov 23, 2003 10:22 pm
by Gen-ik
I'm not sure if you are setting the cookie correctly, the 'time' looks wrong to me.

Shouldn't it be something like this...

Code: Select all

setcookie("login", "yes", time() + 6000);
..but even then the cookie would only be set for 6 seconds.

Try using a function like this...

Code: Select all

function cookie($action, $name, $value="", $hours="")
{
      switch($action)
      {
            case set:
                  setcookie($name, $value, time() + (216000 * $hours));
                  break;
            case get:
                  return $_COOKIE[$name];
                  break;
      }
}

// To set a Cookie...
// It will set the Cookie to exist for 24 hours.
cookie("set", "login", "yes", 24);

// To get the contents of a Cookie...
// $contents will hold the value of the Cookie.. in this case "yes"
$contents = cookie("get", "login");