On Sunday, June 9, 2002, at 12:56 AM, John Taylor-Johnston wrote:
> Absolutely. I've done it. Cookies are cookies. > > What I don't like is that the cookie is not saved unitl after a submit. > > In Javascript, I have JS code that will assign a value and save it to a > cookie and then recall the cookie value and document.write(myvalue), > over and > over if I want, without EVER submitting. It works as the page loads. > > Need JS code? Yes, because it's a client side operation. Remember, it's the submit that is telling the web server to send a cookie. JavaScript code, being client side, can set the cookie without a page submit, just like a mathematical calculation can be done without a page submit in JavaScript but not with PHP. To further this clarification, the reason why you can't read the cookie that you're setting in the same page is because that cookie was never sent to the web server for PHP to recognize. In other words, you may think that because you set a cookie at some point during a given script (that is sent to the user agent), that cookie is now available later in the same script. It's not. The cookie needs to be sent to the web server with a page request in order for the web server/PHP to know it's there. This hasn't happened yet. To beat a dead horse, this is exactly what happens in this order, and the steps are separate: 1. User makes a GET/page request of the web server 2. The resource requested on the web server is a PHP script, and one of its effects is to say "when this resource is sent to the browser, give this cookie along with it" 3. Only AFTER the script executes and is transmitted (thus only AFTER the script is actually done doing its work) does the cookie appear on the client side. So the script is unable to "read" the cookie it is setting. 4. If the user makes another request to that domain, THEN the cookie is available, because the cookie is sent along with that request. In JavaScript, all of this is done on the client side, so the cookie can be read immediately once it is set without the need for requests and page submits or what have you. If you think in terms of HTTP it all makes total sense. Erik ---- Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php