PHP $_COOKIE is never empty... why?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luke14free
    New Member
    • Apr 2007
    • 79

    PHP $_COOKIE is never empty... why?

    Hello,
    I think to have some problem because that code, that is done in order to decide if the page has to have inside the login form (-->user not yet logged) or not(-->user logged).
    [PHP]
    <?php
    setcookie ("autorizzazion e", "", time()-60000);
    //check if the user is logged yet
    //include ("functions.php ");
    if (empty($HTTP_CO OKIE_VARS)){
    include "login.html ";
    echo "2";
    }else{
    //defineaut();
    echo "1";
    }
    ?>
    [/PHP]
    when is executed runs always "1"...

    It means that i have some cookie on my pc but i have deleted manually everyone, and set destroy cookie in line 2...I tried also with

    [PHP]
    if (isset($_COOKIE )){
    [/PHP]
    and
    [PHP]
    if (isset($_COOKIE['autorization'])){
    [/PHP]
    instead of line 5...Is it normal??

    In another page i set the cookie in this way:
    [PHP]
    setcookie('auto rization','2');
    [/PHP]
    and it seems to be ok...Could someone please help me? (my server has PHP 5 and global var ON)
    Thanks,
    Kind Regards, luke14free
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Changed thread title to better match contents.

    Try using print_r($_COOKI E) to see what's in there (such as PHPSESSID, for example).

    Comment

    • luke14free
      New Member
      • Apr 2007
      • 79

      #3
      Yes, thanks for the immediate answer,,,
      (don't worry for the post name! feel always free to make changes! =] )
      [PHP]
      Array ( [autorizzazione] => [82a3f464d4f908c a02a63aae2c0f06 47] => 8c9120502c94ad8 0924b75afff9936 ec [mosvisitor] => 1 )
      [/PHP]
      that's what i get,,,but the cookie should be empty!!! Is it a bug?
      Last edited by luke14free; May 23 '07, 05:15 PM. Reason: wrong tags...

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Originally posted by luke14free
        Yes, thanks for the immediate answer,,,
        (don't worry for the post name! feel always free to make changes! =] )
        [PHP]
        Array ( [autorizzazione] => [82a3f464d4f908c a02a63aae2c0f06 47] => 8c9120502c94ad8 0924b75afff9936 ec [mosvisitor] => 1 )
        [/PHP]
        that's what i get,,,but the cookie should be empty!!! Is it a bug?
        There may always be some extra data in your $_COOKIE array, such as Session ID's (PHPSESSIONID) or something like that.
        In your case there seemes to be a cookie named [mosvisitor], tho I dont know what that is.
        It's never a good idea to assume the $_COOKIE array is empty.

        The best way to use Cookies like this is to check for a specific cookie. I've successfully done this with some of my projects.
        [CODE=php]
        if(isset($_COOK IE['mycookie'])) {
        // User is logged in
        }
        else {
        // User is not logged in
        }
        [/CODE]

        Comment

        • luke14free
          New Member
          • Apr 2007
          • 79

          #5
          I wrote in my original post, in an horrible english that i have already tried to code that way but the result is always the same.
          May it be a server-side problem?
          thanks

          Comment

          Working...