Cookies and Macs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wtso
Forum Newbie
Posts: 1
Joined: Sun Nov 23, 2003 5:07 pm

Cookies and Macs

Post 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";
}
?>
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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");
Post Reply