Re: please explane cookies.



On Fri, 25 Aug 2006 09:40:16 +0200, Frits van Leeuwen wrote:

Hello,
I try to understand cookies.
This is what I have and it's working.

cookies are variables stored in user pc (client) by server.
When client load the page first send to server the variable so
the server knows it.
This is how work cookies.
There are some data that make a cookie:
name for referring it
value ... of course!
the time of live of the valiable
the scope (visibility) of variable.

Think to cookie as an array of these value (name, value, time, scope...)
in client.

Said that there are some function:
setcookie is used to write the value toclient.
$_COOKIES[name_of_variable] for reading it

Probabli the difficult you find in this script i due to
the time of processing it:
The first time you call it just write th cookie.
from the second time the cookie is setted!

INDEX.PHP
-------------
<?php
setcookie("LeeuwendeelTaal","--",time()+31536000);
?>
<html>
<body>
<?php
if (isset($_COOKIE["LeeuwendeelTaal"]))
{
// here a case for NL or EN
print_r($_COOKIE);
echo "<br />Taalcode = " . $_COOKIE["LeeuwendeelTaal"] . "!<br />";
}
else
{
// Here I like to chooce the language
echo "Chooce your language<br />";
}
?>
test3<BR>
</body>
</html>

But....
I do not understand how more now.
When I start INDEX.PHP, I set a cookie. When it is already there, I
overwrite it. But I only like to use the cookie. And when I like, I like to
change the file.

.



Relevant Pages

  • Re: Cross-domain cookie updating ?
    ... It's not strictly a PHP question, but something that PHP guys would know the answer to. ... If the file being returned has updated cookie information in the response header, then I imagine the cookies for example.com get updated. ... What if the JS file it's requesting is actually to a different unrelated domain server that's going to return a JavaScript file with updated cookies in the response header. ... As far as I was aware, the only way a server can set a cookie in the response is by using server-side scripting. ...
    (comp.lang.php)
  • Re: Cross-domain cookie updating ?
    ... It's not strictly a PHP question, but something that PHP guys would know the answer to. ... If the file being returned has updated cookie information in the response header, then I imagine the cookies for example.com get updated. ... What if the JS file it's requesting is actually to a different unrelated domain server that's going to return a JavaScript file with updated cookies in the response header. ... As far as I was aware, the only way a server can set a cookie in the response is by using server-side scripting. ...
    (comp.lang.php)
  • Re: Chicken and egg issue with Cookie based login?
    ... >> Cookies are created by the server, not by the client. ... a client can create a cookie as well. ... The credentials are created when the user logs into the server. ...
    (comp.security.misc)
  • Re: [PHP] base64-encoding in cookies?
    ... PHP application is usually what set the cookie in the first place. ... $_SERVER fields are dependent on your http server. ... but my request is for documentation of the fact ...
    (php.general)
  • Re: Cross-domain cookie updating ?
    ... It's not strictly a PHP question, but something that PHP guys would know the answer to. ... If the file being returned has updated cookie information in the response header, then I imagine the cookies for example.com get updated. ... What if the JS file it's requesting is actually to a different unrelated domain server that's going to return a JavaScript file with updated cookies in the response header. ... As far as I was aware, the only way a server can set a cookie in the response is by using server-side scripting. ...
    (comp.lang.php)