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
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
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.