Results 1 to 8 of 8

Thread: Reading a cookie (Need to brush up this one :D)

  1. #1

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Reading a cookie (Need to brush up this one :D)

    Hey ya,

    I'm writing a (simplish) php / MySQL pop up exchange to use on my site.

    I want the user to be able to store their username and password in a cookie, And so, IF they provide the correct details,
    The cookie gets set like so:

    PHP Code:

        
    // User ID - Username - Password (MD5)
        
    $userinfo base64_encode("$user_id:$username:$password");
        
    setcookie("usercookie","$userinfo",time()+2592000); 
    Any how, so far, i have got by just editing my php nuke site, to include the login, password ETC thats needed (Genious huh)

    Well any how, I want this site to be totally indipendant from my nuke site, (For the main reason, it dont go anything with my nuke site).

    Any how,

    How do i get the cookie READ into the php script?

    Like make it into a variable called "$userinfo" When they call my index.php / login.php / member.php?

    From php nuke (lol) I have been able to find out how i READ it into the user id / username / password

    WHEN i have it as a variable ($userinfo):

    PHP Code:
        $user base64_decode($userinfo);
        
    $cookie explode(":"$user);

        
    $user_id $cookie[0];
        
    $username $cookie[1];
        
    $md5_password $cookie[2];
    // Login stuff goes here IF the cookie is correct,
    // Else
    // setcookie("usercookie"); 
    this is basically a MUST have thing for my "Exchange" as i really doubt users wanna have to login every page etc.

    Ne one help plz?

    TNX
    Wayne

  2. #2

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    OH ALSO:

    How do i set a cookie for 24 hours?

    I want the usercookie to be for a month +,

    But i want to (soon - like before i release my "Exchange Program") make the referals "Cookie Based" cuz people who sign up "Downlines" are given 0.5 credits for every referal's Credit earned, etc..

    And if some1 gave the person a first sight, they should get "Referal Dibs" for 24 hrs (be fair etc )
    Wayne

  3. #3
    New Member
    Join Date
    Sep 2002
    Posts
    14
    For read cookie:

    setcookie("x","1");
    At any page now $x==1 - read as much, as you need

    For 24 hour:
    setcookie("usercookie","$userinfo",time()+86400);
    86400 - sec. in 1day

    If no time-
    setcookie("usercookie","$userinfo");
    cookie will work until you don't close your browser.

    Sincerely,
    Sergey Booyny
    AlarIT programmer
    http://www.AlarIT.com

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by serg4444
    For read cookie:

    setcookie("x","1");
    At any page now $x==1 - read as much, as you need
    As of PHP 4.2, register_globals is off by default.

    It is now the standard to access cookies as: $_COOKIE['x'] rather than the assumed global of $x.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    $_COOKIE variables are also superglobals, meaning they don't have to be setup using the global keyword for use in functions.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    Originally posted by The Hobo
    $_COOKIE variables are also superglobals, meaning they don't have to be setup using the global keyword for use in functions.
    : Now this is something GREAT to know
    : "global $var;" is really Pissy when u have tons of stuff going on huh

    --

    Register_Globals = Off / = On Is on a security risk or ?
    (Wonders) Does it hurt to be on?


    Tnx
    Wayne

  7. #7

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    Is there any problems which could be caused with this php?
    (I tried
    PHP Code:

    // Cookie of the referer's username is "$_COOKIE['referer']"
    // Referer's username which is called by : &ref=*ReferersUserName*
    // $refer: Used later when the person signs up to the "Service".

    if(!isset($_COOKIE['referer'])
    {
        if(
    $ref !=""){
            
    setcookie("referer",$ref,time()+3600);
            
    $refer=$ref;
        }
    } else {

               
    $refer=$_COOKIE['referer'];


    But it wouldn't for the hell of god knows wot,
    Set the cookie with this:

    So i tried:
    PHP Code:
     if ($_COOKIE['referer']==""){
        if(
    $ref !=""){
            
    setcookie("referer",$ref,time()+3600);
            
    $refer=$ref;
        }
     } else {
        
    $refer=$_COOKIE['referer'];
     } 
    And this will work.

    So before i even :think: of releasing my "site", i jst wanna make sure this wont cause problems?

    Tnx
    Wayne

  8. #8

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    Another Quick Question,,,

    I dont want someone (dunno if ppl do this) Sitting @ their site, refreshing their page, for ages, showing their pop up window, And getting credits for it,

    BUT i want them to get like 1 credit for every visitor page view (which im guessing is about 30 seconds, at leaste?)

    What you you guys say the average visitors stay on a single page is?


    Cuz im thinking, i set a cookie when they view a pop up,

    setcookie("lastad","Active:".$uid,time()+30);

    and if i get "$_COOKIE['lastad']" and it is "Active:$uid" i simply dont give em credit for the ad view,

    So, i wanna know the "Average" page view time you guys guess is "Going on" for a "average joe's" site?


    THANKS
    Wayne

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width