SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cookies and PHP 4.2

    My server is still PHP 4.1.2 but I'm upgrading soon so I'm building for 4.2.1.

    I'm having real issues with cookies right now. Never really used them. They seem like they should be easy, but I'm not able to get them working.

    Here's the situtation. I'm collecting information on one of my pages, redirecting to a page on another server, then coming BACK to another of my pages for final processing and db querying. Because of the trip to another server, I am not able to use a session unless I use frames, something I really don't want to do and can't even consider as an option. So, the alternative was a cookie that expires 10 minutes after it is set. So what's wrong with this code that it isn't working? How would I call it, via PHP 4.2.1, on the page 2 steps down the road...?

    PHP Code:
    setcookie('username'$usernametime()+600'''www.barefooting.com'1); 
    Sketch
    Aaron Brazell
    Technosailor



  2. #2
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    afaik - and if i understand you correctly - it's not possible to have cross-site cookies. a page on one server can't set a cookie that can be read by another site. i might be wrong, but this is what i vaguely remember about them...someone please correct me if i'm totally off
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  3. #3
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any chance you could pass the value, encrypted somehow, via the url instead ?
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  4. #4
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the second site won't be using the cookie. I need the cookie for when I return to my site. The brief trip elsewhere is the reason I can't use a session like I normally would.

    Sketch
    Aaron Brazell
    Technosailor



  5. #5
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not to sound like i'm saying RTFM, but maybe the answer lies in one of the user comments at http://www.php.net/manual/en/function.setcookie.php ?
    as i said, i don't work with cookies myself...so i can't be too useful on this one
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, I did RTFM but couldn't find the answer to my problem in the comments...
    Aaron Brazell
    Technosailor



  7. #7
    SitePoint Guru dragonhawk's Avatar
    Join Date
    Apr 2002
    Location
    Melbourne
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works for me

    I set a cookie, the person goes off site to make a payment and comes back and it remembers to cookie.

    In the 4th param, i use "/" to indicate the main directory and "/dirname/" for the directory name. I don't think you can leave it blank.

    So if your domain is http://domain.com and you want to set the cookie for domain.com, set the 4th param to "/"

  8. #8
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm, okay. Maybe I'm trying to use the cookie variable wrong then. How would you use the cookie variable properly?
    $_REQUEST['var']; ?

    Sketch
    Aaron Brazell
    Technosailor



  9. #9
    SitePoint Guru dragonhawk's Avatar
    Join Date
    Apr 2002
    Location
    Melbourne
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I mean set the cookie like so:

    setcookie ("username", $username, time()+600, "/", ".barefooting.com")

    instead of:

    setcookie('username', $username, time()+600, '', 'www.barefooting.com', 1);

    like you have set

    You don't need the 1 at the end...

    When retrieving the cookie, I've got globals on, so I just request $username...

  10. #10
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay, so if I have globals off then I have to redefine username?

    $username = $_COOKIE['username'];

    Is that right?

    Sketch
    Aaron Brazell
    Technosailor



  11. #11
    SitePoint Guru dragonhawk's Avatar
    Join Date
    Apr 2002
    Location
    Melbourne
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can just use $_COOKIE["username"]

    but does the setting of the cookie work?

  12. #12
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    let you know in a minute. I need to make sure I have everything straight here.
    Aaron Brazell
    Technosailor



  13. #13
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope sure didn't
    Aaron Brazell
    Technosailor



  14. #14
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, yes it has. But when I try to do this:
    PHP Code:
    $username $_COOKIE['username'];
    echo 
    $username
    The screen is blank. Put according to phpinfo(), it's a registered cookie.

    Sketch
    Aaron Brazell
    Technosailor



  15. #15
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got it working.
    Very good. Thank you so much.

    Aaron
    Aaron Brazell
    Technosailor



  16. #16
    SitePoint Guru dragonhawk's Avatar
    Join Date
    Apr 2002
    Location
    Melbourne
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anytime


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
  •