Posted by Andy Hassall on 11/16/47 11:34
On Wed, 14 Dec 2005 17:25:50 +0200, shagy <noemail@noemail.com> wrote:
>is it possible to set a with javascript then read that cookie with
>$_COOKIE all within <script language='JavaScript'> tags for example:
>
><script language="JavaScript">
>function test(param) {
> var expiration = new Date();
> expiration.setSeconds(expiration.getSeconds + 30);
> document.cookie = "kae=" + param + ";" + "expires=" +
>expiration.toGMTString() + ";path=/;";
>
> alert(' <?php echo ($_COOKIE['kae']); ?> ');
No, you have the execution order the wrong way around. The PHP code is
executed on the server before it ever reaches the client. The Javascript code
is run on the client afterwards.
The cookie hasn't been set yet when the PHP code runs. You whould end up with
a blank Javascript messagebox (if any).
--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Navigation:
[Reply to this message]
|