Jump to content

Annoying oddity with cookies. Help please


turkman

Recommended Posts

Ok so i had my site working well, i had problems with cookies before. But i got them resolved. Then i wanted to add a log out option to drop the cookie.

 

I have two files reacting differently to the  setcookie("Cookiename","",time()-3600); command.

 

there is two directorys.

 

root directory

root/includes/functions.php

 

functions.php is the file giving me the trouble i think.

 

Ok so  in root directoy i have a file called stuff.php with a link to drop the id, it then calls setcookie and deletes it. Then redirects to index.php.

 

ok. So index.php includes functions.php and calls set_id()

 

set_id() is in functions.php - it tests if the cookie exists, if not it creates one.

 

Now when i log out, it sees that a cookie doesnt exist and creates one and stories it in the database.  All seems to be working fine.

 

However, after that if i were to look at a thread.

 

it would call a function in functions.php

 

in that function, it does _is_admin($_COOKIE['name']); if it returns true then an additional option pops up.

 

so i have just reset my cookie and i can see in the database that set_id() in functions.php has added created a new cookie.

However when the _is_admin() and all other functions in functions.php are called, it still detects the old cookie Which i had before i logged out.

 

Now why would one function in the file act differently from the rest.

 

Sorry if i explained this bad, but its so hard to explain and its annoying.

 

The below functions is in functions.php and recognises there is no cookie and creates a new one.


function set_id(){
        
       
        if(isset($_COOKIE['supercookie'])){
        
                  $v =$_COOKIE['supercookie'];
                  //update cookie
                  setcookie("supercookie",$v,time() + 60 * 60 * 24 * 365);
                  
        
        }
        else{
        $charlist =  "abcdefghijklmnopqrstuvwxyz0123456789";
        $c = "";
        
        for($i = 0; $i < 25; $i++ ){
        
              
              $r = rand() % strlen($charlist);
              $c .= $charlist[$r];
        
        
        }
        
        setcookie("supercookie",$c,time() + 60 * 60 * 24 * 365);
        setcookie("FirstArrived","dfffff",time()+60);
        addaction(9,"Set New id.");
        
        mysql_query("INSERT INTO pword (level,lv,scookie) VALUES ('Norm','0','$c')")or die(mysql_error());
        }
        

}

 

however any other function in functions.php that calls $_cookie['supercookie'] always seems to be returned the admin cookie which i had before i "logged out"

 

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.