what i dont understand is , when using cookies in a php script , that script is executed in the server side and the cookie itself is in the client browser memory,
how the server know his own cookies ?
when the user/browser request a php page from the server the browser send first all cookies that is correspond to this domain to the server "we dont see that " ,
for example : browser >> GO to www.somewebsite.com/dir1/dir2/foo.php
the browser duty is first to find if it has any cookies related to this domain and if it has it send it together with the request and it is stored by php in $_COOKIE global variable, then the script in foo.php process this cookie further more like changing or deleting it.... am i right ?
setcookie() work the opposite direction , it set the new created cookie and send it to the page in its header and the browser save it locally for local use like in javascript...am i right ?
please tell me if i understand ? thanks.
5 replies to this topic
#1
Posted 09 January 2011 - 01:05 PM
|
|
|
#2
Posted 09 January 2011 - 03:54 PM
The server will request the cookie, which the browser provides. It's handled fairly transparently.
#3
Posted 09 January 2011 - 04:49 PM
read this if it helps: Cookies | Practical PHP Programming | TuxRadar Linux
#4
Posted 09 January 2011 - 05:40 PM
Client:
The browser will match domain, path and connection type (http or ssl) and if matches will send the cookie along with the request, an example HTTP request from the client browser to the server:
Server:
When setcookie() is called, it will send an HTTP request named Set-Cookie, an example of setting the cookie and sending it to the client is as follows:
The browser will match domain, path and connection type (http or ssl) and if matches will send the cookie along with the request, an example HTTP request from the client browser to the server:
GET /index.html HTTP/1.1 Host: www.example.com Cookie: name=value Accept: */*Note that Apache will populate PHP's $_COOKIE superglobal array with the content of the cookies sent, in this case $_COOKIE['name'] = 'value'.
Server:
When setcookie() is called, it will send an HTTP request named Set-Cookie, an example of setting the cookie and sending it to the client is as follows:
HTTP/1.1 200 OK Content-type: text/html Set-Cookie: name=valueThen it is the client browsers responsibility to handle the cookie and store it. The request is dependent on parameters, for example if you use a more complex setcookie call like this:
setcookie("name", "value", time() + 3600, "/", ".example.com");It can populate this response:Set-Cookie: name=value; expires=Fri, 31-Jan-2011 10:00:59 GMT; path=/; domain=.example.com
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#5
Posted 09 January 2011 - 10:10 PM
hi guys thank you for the help
but alexander you say that apache will populate $_COOKIE superglobal ,
but i think apache is just a web server that transform php to html and serve the pages to the client ,
i am not sure if you are right because i think its php parser duty to populate the $__COOKIE superglobal variable..
please correct me if i am wrong...
thank you all again
but alexander you say that apache will populate $_COOKIE superglobal ,
but i think apache is just a web server that transform php to html and serve the pages to the client ,
i am not sure if you are right because i think its php parser duty to populate the $__COOKIE superglobal variable..
please correct me if i am wrong...
thank you all again
#6
Posted 10 January 2011 - 12:24 AM
Apache will collect the cookie information sent from the client in a environment variable and forward it to PHP which populates the $_COOKIE variable based upon the forwarded information. So apache do indirect populates the $_COOKIE variable.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









