Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Site-wide PHP cookies

  • 27-02-2002 05:15PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2, Paid Member Posts: 14,174 ✭✭✭✭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, Registered Users 2, Paid Member Posts: 14,174 ✭✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 68,173 ✭✭✭✭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