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

    Join Date
    Dec 1999
    Ekaterinburg, Ural, Russia
    Rep Power
    Thank you for reading this.

    I'm setting cookie with PHP3 function
    setcookie(); in one script.
    I get no warning while processing
    the script, but when I try to read the
    cookie in another script nothing is returned. I tried several combinations, but still no result.
    Can you tell me what's the problem?

    Thank you a priori.

    Sincerely yours,
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Rep Power
    Format for setting cookies:
    <?php setcookie("theuser",$Username,time()+31536000); ?>
    (Do this at the top of the page before you do anything else like send headers or it doesn't work.)

    theuser=cookie name
    $Username=what is set
    time()+31536000=time in seconds

    If you set a cookie for time(), that's a trick for having it expire immediately. That may be your problem.

    Retrieving cookies: $theuser.

    btw- This isn't really an advanced question, or I wouldn't know the answer. lol.
    So you'll get more replies next time if you don't title it that way.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Rep Power
    I always had trouble with cookies also. But how can i set a cookie that'll never expire?
  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Rep Power

    you can check wether cookie has been set or not using..

    if (isset($cookiename)){
    echo "Cookie has been setn";
    echo "could not set cookien";

    here is a cookie example.

    setcookie("cookiename","cookie value",time()+14400,"/","www.yourdomain.com");

    make sure that you are passing the values to 4th and 5 th argument.Otherwise your cookie won't available through out your site.

    you can retreive a cookie using cookiename.
    echo $cookiename;

    Good Luck!!!

    SR -
    www.jobxyz.com-IT Career Portal

    "The fear of the LORD is the beginning of knowledge..."

Similar Threads

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

IMN logo majestic logo threadwatch logo seochat tools logo