PHP Cookie is not working,,,,

Discussion in 'PHP' started by gr8webseller, Jan 28, 2010.

  1. #1
    Now i am currently coding a PHP site and i am implementing the login page for my site, but the remember me feature in my script is not working,,,

    here is the code which i placed in header.php after the body tag,,,

    <?php
       if(isset($_COOKIE['username']) && isset($_COOKIE['userid']))
       {
          $_SESSION['USERNAME'] = $_COOKIE['username'];
          $_SESSION['USERID'] = $_COOKIE['userid'];
       }
    ?>
    PHP:
    this is the code which i placed in login.php

     if(isset($_POST['remember']))
                {
                    setcookie("username", $_SESSION['USERNAME'], time()+60*60*24*100, "/");
                    setcookie("userid", $_SESSION['USERID'], time()+60*60*24*100, "/");
                }
    PHP:
    i selected remember me option while loging in and i logged in,,, after that i closed the browser without loging out,,,,, when i open the page again it is not auto loging,,, please help me with this,,,
     
    gr8webseller, Jan 28, 2010 IP
  2. HivelocityDD

    HivelocityDD Peon

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    are you getting the cookie data ?

    Please try printing out the cookie data

    print_r($_COOKIE)

    and see its there. I think you might be needing to set the cookie path also if your $_COOKIE is not having those keys.
     
    HivelocityDD, Jan 28, 2010 IP
  3. nice12

    nice12 Member

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    You can't put it after the body tag. You have to check for the cookies before headers are sent.
    Use headers_sent function to check.
     
    nice12, Jan 28, 2010 IP
  4. codebreaker

    codebreaker Well-Known Member

    Messages:
    281
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #4
    What are you tring to do it's very dangerous.
    Your way if i know the username and the userid i can login in the user account.
     
    codebreaker, Jan 29, 2010 IP
  5. gr8webseller

    gr8webseller Peon

    Messages:
    1,097
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i tried this, but nothing is printed

    i placed the script about doctype, but still no result

    i know, i am first checking the cookie function without database,,,
     
    gr8webseller, Jan 29, 2010 IP
  6. gr8webseller

    gr8webseller Peon

    Messages:
    1,097
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thank you very much, it works great,,,
     
    gr8webseller, Jan 29, 2010 IP
  7. jNorth

    jNorth Peon

    Messages:
    202
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    we will just pretend you didn't say this
     
    jNorth, Jan 29, 2010 IP