Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Site-wide PHP cookies

Options
  • 27-02-2002 5:15pm
    #1
    Registered Users Posts: 2,518 ✭✭✭


    Is there any way to access a cookie that has been set using setcookie() in one php script, from another php script ?


Comments

  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    If the scripts are on the same domain name, and under the same path, you should be able to access cookies vars by default. Echo the $HTTP_COOKIE_VARS array to the browser to have a look:

    print_r($HTTP_COOKIE_VARS);

    If the path isn't set specifically in the setcookie() call, you may be locked into directories below the current script. The solution is to set it properly in the setcookie call.

    See the manual for setcookie and the Netscape cookie spec for more info.

    adam


  • Registered Users Posts: 14,148 ✭✭✭✭Lemming


    To (try) answer your question, and as far as my understanding of cookies goes (not much), so long as you have the "session_start()" call somewhere at the start of your php script, you can use whatever cookies have been created so long as they have not been destroyed.

    I'm sure dahamsta WILL correct me here if I'm wrong :p


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Heh, Lemming's wrong. session_start() is used for sessions, not cookies, ya divvy! :)

    adam


  • Registered Users Posts: 14,148 ✭✭✭✭Lemming


    Originally posted by dahamsta
    Heh, Lemming's wrong. session_start() is used for sessions, not cookies, ya divvy! :)

    adam

    See .. I told ya he'd correct me :p

    But don't sessions use cookies (of sorts)??


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    See .. I told ya he'd correct me :p

    We aim to please. :)

    But don't sessions use cookies (of sorts)??

    If they're available, yes, they use a cookie to store the user's session id, which is associated with records on the server side. Alternatively, they can be propogated in the URL, either manually using the constant SID or automatically if PHP is compiled with --enable-trans-sid.

    Still though, not the same. :)

    adam


  • Advertisement
  • Registered Users Posts: 2,518 ✭✭✭Hecate


    I printed out that header variable and this is what I got back from it:

    Array ( [sid] => 1086069691 )

    This is after sending a cookie to the browser in the previous script with setcookie("session_username", $username, time()*3600);

    The thing is I've tried accessing cookie set variables from other scripts and they just appear to be empty.


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    I was learning about this yesterday.......Can you just not set the cookies so that they are accessible for the whole domain?

    $mycookie=cookie(......................
    ......................
    -domain => mydomain.com)

    ?
    :) (Or maybe I'm thinking of the wrong language?)


Advertisement