Thread: Cookies

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    5
    Rep Power
    0
    In short: How do cookies work?

    In long:
    I want to set a cookie as a user logs into the system, i want the cookie(or cookies) to hold his username and password, then i want him to be able to go where ever without having to re-enter his username/password either untill he logs out, or his cookie expires..

    any suggestions?

    ------------------
    -Mike
    Thanks for any help
    [url]http://209.161.8.36/
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    2
    Rep Power
    0
    Here is some example code I've whipped together for you....

    <?
    if($action == "setcookie") {
    setcookie("vis_name", $visitorname, time() + 3600);
    // expires in one hour
    }
    if (isset($vis_name)):
    // if cookie is set, display it
    ?>

    <font face="Verdana" size="1">
    <b><center>
    <?
    $msgline = "The Company welcomes " . $vis_name . "!";
    print("$msglinen");
    ?>
    </b></center>
    </font>

    <? else: ?>

    <div align="center"><center>
    <font face="Verdana" size="1">
    Personalize Your Company! [Enter Name Below]<br>
    <form><b>
    <input type="hidden" name="action" value="setcookie">
    <input type="text" name="visitorname" size="15" value="Insert Name" tabindex="1" maxlength="35">
    <input type="submit" value=" OK! " tabindex="2">
    </font></b></strong>
    </form>
    </div></center>

    <? endif; ?>

    Hope this code is a little help on what cookies are all about, and if you want, stop on over to http://evilwalrus.com and check it out, we offer tons of free scripts (user submitted) and I've implemented my little "cookie system" on my site, just to spice things up a bit...



    ------------------
    Evil Walrus
    AKA: Andrew Heebner
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    5
    Rep Power
    0
    Ok, cookies i understand now, i was up till 3am writing my little script, it's up to about 500 lines now, uhm..one thing, how would i make a cookie set for a ip address domain, e.g. 10.1.1.1
    cuz, i dont exactly have a domain name for my server yet...
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    2
    Rep Power
    0
    I don't have a clue how to use cookies for IP address's.. probably something along these lines....

    <?
    $server = "10.1.1.1";
    setcookie("COOKIE_NAME", $cookie_val, $server);
    ?>

    I really don't have a clue on this one... lets leave it to these BrainDump braniacs



    ------------------
    Evil Walrus
    AKA: Andrew Heebner
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    5
    Rep Power
    0
    well, that does'nt work, i know for a fact, i've tried that already hehe , if we must, for now i just have vhosts setup with apache on my server both pointing to the same ip, so it covers both my hostnames ..just, alotta extra work involved there..oh well, it's off to formatting the HTML to make the site look perty
  10. #6
  11. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    # the following will set the cookie in the root directory of your domain(you can replace that with ipnumber).

    setcookie("vis_name", $visitorname, time() + 3600,"/","www.yourdomain.com","");



    ------------------
    SR -
    shiju.dreamcenter.net

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

Similar Threads

  1. cant delete cookies random errors
    By toxical in forum PHP Development
    Replies: 2
    Last Post: November 26th, 2003, 06:16 AM
  2. Clearing all cookies php script - HowTo?
    By fordfasterr in forum PHP Development
    Replies: 8
    Last Post: October 24th, 2003, 10:40 AM
  3. Problem with lwp and cookies
    By vinaykakade in forum Perl Programming
    Replies: 1
    Last Post: August 13th, 2003, 11:07 AM
  4. Problems setting cookies with a path and domain
    By IBBoard in forum PHP Development
    Replies: 4
    Last Post: July 2nd, 2003, 04:03 PM
  5. AOL cookies?
    By cfthong in forum PHP Development
    Replies: 0
    Last Post: August 18th, 2000, 11:59 AM

IMN logo majestic logo threadwatch logo seochat tools logo