Results 1 to 12 of 12

Thread: anybody know how to make cookies in php?

  1. #1
    Join Date
    Dec 2002
    Location
    hell
    Posts
    1,645

    anybody know how to make cookies in php?

    i already used the code setcookie('variable', $variable, time blabla)

    then retrieving it by $_COOKIE('variable')

    but it doesnt work.

    what am i doing wrong?

  2. #2
    I'ts been a while since I've played with cookies (I normally just use sessions) But as far as I can remember you cannot get the cookie on the same request as you set it.... But I'm not 100% sure though

  3. #3
    Join Date
    Dec 2002
    Location
    hell
    Posts
    1,645
    my site is using sessions right now...

    problem is, based from what i researched to know whether a visitor has entered your site before or not is by using cookies...
    cookies are used to save the variables on the users computer so they will not have to enter the details again...

    anybody know any other way to go around this?

    i have been researching around on the net but as of now i havent found anything applicable to my site...

    i am using mysql too, if thats any importance...

    im not sure what versiion of php coding im using but i think theres a standard so i wont bother with that... hehehe

    i just want to grant all the requests that are coming....

  4. #4
    Hmm. Well sessions automatically use cookies. So if your session is working, cookies also should work.
    Anyhow. What I have done is set the session timeout as a default to 3 months (I think). But you should be able to use cookies if you want to. It's hard to know what's wrong without seeing an example.


    And also. Just so you know it.... Opera and Netscape very often have trouble with cookies that IE doesn't have trouble with.


    Oh... And a nother thing I thought of... Make sure that the date and time are correct both on your server and on your pc.... I spent two days trying to figure out why a site I made wasn't working with cookies. It turned out that the server date was set to 1998. So IE got cookies that expired in 1998, and just skipped them since they were 5 years outdated.

  5. #5
    sorry i dont know

  6. #6
    Join Date
    Mar 2003
    Location
    Vienna, Austria
    Posts
    12
    hmmm

    maybe your cookie-time is too short?

    setcookie ("TestCookie", $value, time()+3600); /* ok for 1 hour */

    maybe your IExplorer blocks the cookie?

  7. #7
    Join Date
    Dec 2002
    Location
    hell
    Posts
    1,645
    this is an example...

    $cookie_life = time() + 31536000;
    $path = '/jesteruk/folder/';
    $hostname = 'evolt.org';

    setcookie('username', $name, $cookie_life, $path, $hostname);



    // Our cookie would be contained in

    $HTTP_COOKIE_VARS['username']

    // or

    $_COOKIE['username']





    anything wrong with this code?

  8. #8
    Join Date
    Mar 2003
    Location
    Vienna, Austria
    Posts
    12
    setcookie ("TestCookie", $value, time()+3600, "AAAAA", "BBBBB",1);

    echo $TestCookie;
    echo $HTTP_COOKIE_VARS["TestCookie"];

  9. #9
    Join Date
    Dec 2002
    Location
    Belgium
    Posts
    194
    u have to do a setcookie..then the user will save on on his pc

    depending on the domain u use in the cookie..when that user
    connects to a page of that domain, the browser will automaticly
    send the cookie values to your server

    for example if u used setcookie('username', $name, $cookie_life, $path, $hostname);

    then..on (every) page u want to recognize the user..use something like this:

    echo "welcome back, $username";


    and the guy will see his name on the screen

  10. #10
    Join Date
    Mar 2003
    Location
    London
    Posts
    405
    can anyone here help me with some php coding?

    i have a mysql database and i want to do a search which allows results to be displayed in a table. From this table i want to have a button which addres information into a shopping cart.

    What is the best way to display the results in a table (after the while ($row = mysql_fetch_row ($result)) bit) and have the button:

    <a href="cart.php?action=add_item&id=<?php echo $row["itemId"]; ?>&qty=1">Add Item</a>

  11. #11
    Join Date
    Dec 2002
    Location
    hell
    Posts
    1,645
    is this correct?
    im trying to retrieve these cookie code:

    <?php
    $cookie_life = time() + 31536000;
    $hostname = 'franchesca.org';
    setcookie('name', $name, $cookie_life, $hostname);
    ?>

    so this is what im doing to retrieve it, and check if its empty or not....

    <?php
    $_COOKIE['name'];
    if ( $name != '' )

    ?>
    Last edited by schizo; 30-03-2003 at 09:08 AM.

  12. #12
    Join Date
    Mar 2003
    Location
    Vienna, Austria
    Posts
    12
    to ask a string if "he" is empty i'm useing

    if (!$mystring) $mystring = 'ABC';


    walter

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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