cookies

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shagy

    cookies

    is it possible to set a with javascript then read that cookie with
    $_COOKIE all within <script language='JavaS cript'> tags for example:

    <script language="JavaS cript">




    function test(param) {


    var expiration = new Date();
    expiration.setS econds(expirati on.getSeconds + 30);
    document.cookie = "kae=" + param + ";" + "expires=" +
    expiration.toGM TString() + ";path=/;";

    alert(' <?php echo ($_COOKIE['kae']); ?> ');
    }




    should this be working?
    The alert box doesn't appear at all

    Any help would be appreciated.

    shagy :-)
  • Andy Hassall

    #2
    Re: cookies

    On Wed, 14 Dec 2005 17:25:50 +0200, shagy <noemail@noemai l.com> wrote:
    [color=blue]
    >is it possible to set a with javascript then read that cookie with
    >$_COOKIE all within <script language='JavaS cript'> tags for example:
    >
    ><script language="JavaS cript">
    >function test(param) {
    > var expiration = new Date();
    > expiration.setS econds(expirati on.getSeconds + 30);
    > document.cookie = "kae=" + param + ";" + "expires=" +
    >expiration.toG MTString() + ";path=/;";
    >
    > alert(' <?php echo ($_COOKIE['kae']); ?> ');[/color]

    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.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Sjoerd

      #3
      Re: cookies

      The PHP is executed before the page is sent to the client. The
      Javascript is executed when the page is received by the client.

      Comment

      Working...