#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    I am trying to get a handle on setting and retrieving cookies. I think I might have it down, but I'm not sure... if anyone can help, please reply.

    to set a cookie, I have only two variables, the user name ($user) and their password ($password)... okay, so I want to set this cookie after they logon.

    I use: (this is more of a question than a statement)

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    setcookie("username",$user,time()+31536000);
    setcookie("password",$password,time()+31536000);
    [/code]

    and this should set the cookie(s), right? I think this should go before the <html> or <head> tags in my page (so basically, the VERY first thing in my page should be this, if I'm setting the cookies)


    To retrieve the cookies, I use : (again, another question based statement)


    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    ....
    [/code]

    okay, so I don't know how to retrieve information from the cookie.

    Any help would be greatly appreciated, correcting my setcookie code, and completing my retrieval information. I am kinda new to php, not totally dumb to programming, but lost on cookies <G>

    Thanks,
    Mike

  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    your setup cookie is correct..

    i am writing an easy example for cookie:

    setcookie("CookieID", $USERID);


    To retrieve the cookies from above example you can use..

    print $CookieID;

    ie,Name of the cookie..

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    Alright, so if the top of my web page looked like this:

    <?php3
    setcookie("username",$user,time()+31536000);
    setcookie("password",$pwrd,time()+31536000);
    ?><HTML><HEAD> ...........rest of page ....

    that would set my cookie, and later in the site I use $username and $password as my variables to reference their cookie? There's no "getcookie" function or anything?

    Thanks,

    Mike




    ------------------
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Location
    Netherlands
    Posts
    77
    Rep Power
    16
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by mmccue:
    Alright, so if the top of my web page looked like this:

    <?php3
    setcookie("username",$user,time()+31536000);
    setcookie("password",$pwrd,time()+31536000);
    ?><HTML><HEAD> ...........rest of page ....

    that would set my cookie, and later in the site I use $username and $password as my variables to reference their cookie? There's no "getcookie" function or anything?

    Thanks,

    Mike

    [/quote]

    Hi Mike,

    If the cookies have been set, then you can simply refer to their values in other php pages (within the same domain/directory the cookie is set in) with the variables $username and $password.

    Try this to see whether the cookies are there:

    Make a file (viewcookie.php3 or so), like:

    <?
    if(isset($username) and isset($username))
    {
    print $username . "<BR>n";
    print $password . "<BR>n";
    }
    else { print "No cookies have been set!"; }
    ?>

    Have a nice meal!

    Peter

    [This message has been edited by PAV (edited April 04, 2000).]
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    Thanks both of ya for your help... I played with it, and got it to work on my third or fourth try.... Kept forgetting the "+" after the "time()" statement....


    Just wanted to let ya know your help is appreciated.

    Mike


    ------------------

Similar Threads

  1. php "my favorites"...creating cookies to save links..
    By terminal in forum PHP Development
    Replies: 2
    Last Post: February 8th, 2004, 04:25 PM
  2. PHP: cookies
    By theodore in forum PHP Development
    Replies: 1
    Last Post: January 21st, 2004, 10:39 PM
  3. PHP with UnixODBC
    By coder4hire in forum PHP Development
    Replies: 2
    Last Post: January 20th, 2004, 02:14 PM
  4. Passing string from PHP to Javascript
    By ka8oad in forum JavaScript Development
    Replies: 4
    Last Post: January 17th, 2004, 04:12 PM
  5. UnixODBC + PHP + Apache + Empress
    By coder4hire in forum Database Management
    Replies: 0
    Last Post: January 15th, 2004, 02:41 PM

IMN logo majestic logo threadwatch logo seochat tools logo