Jump to content

setcookie() help


FrostedFlakes1024

Recommended Posts

For some reason I can not get this to work. Any thoughts?

 

        if( $row['password'] == $pass && $row['name'] == $user )
        {
          $username = $row['name'];
          $uid = $row['id'];
          setcookie("id", $uid, 1400); //creates the first session var
          setcookie("username", $username, 1400); // second session var
          setcookie("loggedin", "1", 1400);

          echo "<script type=\"text/javascript\">alert(\"".$row['name']."Logged in as ".$_COOKIE['username'].".\"); window.location=\"index.php?OMG=loggedin\"</script>";
        }

 

I get a message box saying: "[username] Logged in as ."

I've searched php.ini for corrupt cookie settings, nothing unusual.

Link to comment
https://forums.phpfreaks.com/topic/211696-setcookie-help/
Share on other sites

1. cookies are read from the header

2. setting cookie goes into the header (hence before any output)

3. expire is a unix DATE & time (not just seconds)

if( $row['password'] == $pass && $row['name'] == $user )
        {
          $username = $row['name'];
          $uid = $row['id'];
          setcookie("id", $uid, time()+1400); //creates the first session var
          setcookie("username", $username, time()+1400); // second session var
          setcookie("loggedin", "1", time()+1400);
//Cookie won't be set visible until a the header loads (next page)
          echo "<script type=\"text/javascript\">alert(\"".$row['name']."Logged in as ".$username.".\"); window.location=\"index.php?OMG=loggedin\"</script>";
        }

Link to comment
https://forums.phpfreaks.com/topic/211696-setcookie-help/#findComment-1103551
Share on other sites

Archived

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.