Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about cookies with PHP 1

Status
Not open for further replies.

Guggly

Programmer
Joined
Jan 18, 2004
Messages
110
Location
US
Quick question, since PHP runs server-side, if I set/retrieve a cookie in my PHP script will it do so on the client machine or on the server? If it uses cookies on the server than I'll have to use JavaScript to do this, but if PHP works with cookies client-side than that's great!

Thanks! -- Mike
 
Cookies only exist on the client. PHP's set_cookie() function will set a cookie on the browser for you.

One thing to be aware of....

Cookies are sent as a part of the HTTP headers that precede the content of a page. You must use set_cookie() before you begin sending content to the browser or you will get an error. I have an more-indepth explanation in my FAQ on debugging PHP code: faq434-2999

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks! Guess that's an exception to the usual server-side running that PHP does. Out of interest, are there other functions that PHP implements client-side?

Thanks! -- Mike
 
There are none. No PHP function runs on the client-side, including set_cookie().

set_cookie() just sends out a string at the right time that the browser interprets in a useful way. This is no different that using print() to output HTML.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top