SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: PHP & Cookies

  1. #1
    Who Me? JeremyL's Avatar
    Join Date
    Dec 1999
    Dallas, TX
    0 Post(s)
    0 Thread(s)
    How is it possible to add cookies to a user if the code does not show any code that would add the cookies. I have seen this done on a site that does use php but they do not have any javascript in the code that would add or read the cookies. How are they doing this?

  2. #2
    SitePoint Community Guest
    the cookies are read on the server's side and the page is generated accordingly

    Vinay Sahni (, Coder .. specializing in php/mysql
    ( Realmz ) ( ReviewDepot ) ( . . : : k r y o g e n : : . . )

  3. #3
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Lancaster, Ca. USA
    1 Post(s)
    0 Thread(s)
    They are added in the response headers of the webpage. ASP works the same way.

    When you type in an address or click on an URL to go to a page the browser sends a heck of a lot of info to the server. This includes IP address, Referring URL, any cookies you might have for that site, posted form responses and so forth. This is all behind the scenes. These are the request headers.

    When the server starts to send the webpage back it includes its own group of headers these can include cookies. These are the response headers.

    When the browser recieves cookies in the response headers it will write them to the hard drive, overwriting what does exist as long as it doesn't overflow the 4K barrier. Not only ASP and PHP can do this but any server side process can add cookies to the Response headers if programmed properly.

    I don't know how PHP works but in ASP there is a Response object and it has a cookies collection that can be added to as needed. When you want to read cookies from the user then you would use the Request object's corresponding cookie collection. I am sure PHP has similar objects and collections.

    Wayne Luke - Sitepoint Moderator/Internet Media Developer
    Digital Magician Studios - Making Magic with Web Applications


Posting Permissions

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