Professional Web Applications Themes

beginner cookie think - PHP Development

hi all, Trying to get those cookies to work but they wont... Doing this. Have a page login.php wich tests the user and pass. If they are correct a cookie is set with one variable like this: setcookie ("cookieUser", $user); then the browser is sent with header("Location: spelersPage.php"); to another page. I there try to read the cookievariable cookieUser on the spelersPage.php like this. <? $test = $_COOKIE["cookieGebruiker"]; echo "|$test"; ?> without any succes. Someone has an idea. The page is im my Thrusted sites list... kind regards Stijn...

  1. #1

    Default beginner cookie think

    hi all,

    Trying to get those cookies to work but they wont...

    Doing this. Have a page login.php wich tests the user and pass. If they are
    correct a cookie is set with one variable like this: setcookie
    ("cookieUser", $user);
    then the browser is sent with header("Location: spelersPage.php"); to
    another page.
    I there try to read the cookievariable cookieUser on the spelersPage.php
    like this.
    <?
    $test = $_COOKIE["cookieGebruiker"];
    echo "|$test";
    ?>

    without any succes. Someone has an idea. The page is im my Thrusted sites
    list...

    kind regards
    Stijn




    Stijn Goris Guest

  2. #2

    Default Re: beginner cookie think


    "Stijn Goris" <mepistohotmail.com> wrote in message
    news:3f622bb2$0$24129$ba620e4creader1.news.skynet .be...
    > hi all,
    >
    > Trying to get those cookies to work but they wont...
    >
    > Doing this. Have a page login.php wich tests the user and pass. If they
    are
    > correct a cookie is set with one variable like this: setcookie
    > ("cookieUser", $user);
    > then the browser is sent with header("Location: spelersPage.php"); to
    > another page.
    > I there try to read the cookievariable cookieUser on the spelersPage.php
    > like this.
    > <?
    > $test = $_COOKIE["cookieGebruiker"];
    > echo "|$test";
    > ?>
    >
    > without any succes. Someone has an idea. The page is im my Thrusted sites
    > list...
    >
    > kind regards
    > Stijn
    >
    >
    >
    >
    Your problem is likely due to a limitation to cookies, not php.

    A refresh has to have occured before your cookie becomes available to your
    environment thus if you were to refresh your browser a couple of times you
    should get your cookie. If not, as a test, I tend to use phpinfo(); alot
    when doing various tests on form and cookie variables... Try writing the
    following few lines to a php script file of its own (call it cookieTest.php
    for our example).

    <?
    // For our test, our cookie will be the words "hello world" followed by the
    eleven digit timestamp generated by time();
    $ourCookie="hello world" . time();
    setcookie("ourTestCookie", $ourCookie);
    print("<br>1 = The cookie we just set is $ourCookie<br>");
    print("<br>2 = However the cookie that is already baked is:
    $_COOKIE[ourTestCookie]");
    phpinfo();
    ?>

    View this code in a page of its own... refresh the page a few times and
    examine the values that are output - and while you're at it, examine the
    output of phpinfo();.

    I would expect that you should find something like

    1 = The cookie we just set is hello world12345678901
    2= However the cookie that is already baked is:

    The next time your refresh your browser, you should find the output
    something like the following

    1 = The cookie we just set is hello world12345678911
    2= However the cookie that is already baked is:hello world12345678901

    Note that the cookie the first time was sent to the browser but could not be
    read yet (until you re-freshed the browser).


    Randell D. Guest

  3. #3

    Default Re: beginner cookie think


    ----- Original Message -----
    From: "Randell D." <you.can.email.me.at.randelld>
    Newsgroups: comp.lang.php
    Sent: Friday, September 12, 2003 10:42 PM
    Subject: Re: beginner cookie think

    >
    > "Stijn Goris" <mepistohotmail.com> wrote in message
    > news:3f622bb2$0$24129$ba620e4creader1.news.skynet .be...
    > > hi all,
    > >
    > > Trying to get those cookies to work but they wont...
    > >
    > > Doing this. Have a page login.php wich tests the user and pass. If they
    > are
    > > correct a cookie is set with one variable like this: setcookie
    > > ("cookieUser", $user);
    > > then the browser is sent with header("Location: spelersPage.php"); to
    > > another page.
    > > I there try to read the cookievariable cookieUser on the spelersPage.php
    > > like this.
    > > <?
    > > $test = $_COOKIE["cookieGebruiker"];
    > > echo "|$test";
    > > ?>
    > >
    > > without any succes. Someone has an idea. The page is im my Thrusted
    sites
    > > list...
    > >
    > > kind regards
    > > Stijn
    > >
    > >
    > >
    > >
    >
    > Your problem is likely due to a limitation to cookies, not php.
    >
    > A refresh has to have occured before your cookie becomes available to your
    > environment thus if you were to refresh your browser a couple of times you
    > should get your cookie. If not, as a test, I tend to use phpinfo(); alot
    > when doing various tests on form and cookie variables... Try writing the
    > following few lines to a php script file of its own (call it
    cookieTest.php
    > for our example).
    >
    > <?
    > // For our test, our cookie will be the words "hello world" followed by
    the
    > eleven digit timestamp generated by time();
    > $ourCookie="hello world" . time();
    > setcookie("ourTestCookie", $ourCookie);
    > print("<br>1 = The cookie we just set is $ourCookie<br>");
    > print("<br>2 = However the cookie that is already baked is:
    > $_COOKIE[ourTestCookie]");
    > phpinfo();
    > ?>
    >
    > View this code in a page of its own... refresh the page a few times and
    > examine the values that are output - and while you're at it, examine the
    > output of phpinfo();.
    >
    > I would expect that you should find something like
    >
    > 1 = The cookie we just set is hello world12345678901
    > 2= However the cookie that is already baked is:
    >
    > The next time your refresh your browser, you should find the output
    > something like the following
    >
    > 1 = The cookie we just set is hello world12345678911
    > 2= However the cookie that is already baked is:hello world12345678901
    >
    > Note that the cookie the first time was sent to the browser but could not
    be
    > read yet (until you re-freshed the browser).
    >
    >
    Hi,

    Thanks for your reply. Indeed, when I refresh the page where the cookie is
    defined, the cookievariable is set. What is the best way to overcome this
    cookielimitation? Do I have to use some sort of javascript refresh while the
    setcookie page is accessed or is there an other way (pref. in php) to
    overcome this problem...
    I want to use the cookie for an automated login (often used with forum
    systems where 'Log me on automatically each visit' is used ). How do they
    deal with this limitation?

    regards
    Stijn

    kind regards
    Stijn


    Stijn Goris Guest

  4. #4

    Default Re: beginner cookie think

    (dolphin talk) eeeeeekkkkkk squueeeekkkkk Stijn Goris eeeeeiiiiiiikkkkkkkk
    squeeeeekk Fri, 12 Sep 2003 20:02:59 -0500, eeeeeiiiiiiieeeeeekkkk
    eeeeekkkkkk eeiiikkkk <3f62691c$0$5561$ba620e4creader2.news.skynet.be >:

    > ----- Original Message -----
    > From: "Randell D." <you.can.email.me.at.randelld> Newsgroups:
    > comp.lang.php
    > Sent: Friday, September 12, 2003 10:42 PM Subject: Re: beginner cookie
    > think
    >
    >> "Stijn Goris" <mepistohotmail.com> wrote in message
    >> news:3f622bb2$0$24129$ba620e4creader1.news.skynet .be...
    >> > hi all,
    >> >
    >> > Trying to get those cookies to work but they wont...
    >> > [...]
    >> >
    >> Your problem is likely due to a limitation to cookies, not php.
    >>
    >> A refresh has to have occured before your cookie becomes available to
    >> your environment
    >> [...]
    >>
    > Hi,
    >
    > Thanks for your reply. Indeed, when I refresh the page where the cookie
    > is defined, the cookievariable is set. What is the best way to overcome
    > this cookie limitation? [...]
    Hi Stijn

    To overcome the need to refresh, set the cookie's value
    in *both* the HTTP response header and the $_COOKIE array
    at the same time:

    $_COOKIE['mycookie'] = 'chocolate chip';
    setcookie('mycookie', $_COOKIE['mycookie']);

    If you synchronize the HTTP response and the $_COOKIE
    array on the first page that sets the cookie, you won't
    have to refresh.

    HTH

    This message is under the GPL.

    Gary Petersen Guest

Similar Threads

  1. Beginner Please help!
    By Nemuel in forum Dreamweaver AppDev
    Replies: 7
    Last Post: May 7th, 07:42 AM
  2. HTTP::Cookie won't store sent cookie
    By Richard Lawrence in forum PERL Modules
    Replies: 4
    Last Post: March 21st, 12:38 PM
  3. Beginner here!
    By Lisa K. in forum Web Design
    Replies: 1
    Last Post: November 18th, 03:28 AM
  4. Replies: 7
    Last Post: September 5th, 06:28 PM
  5. authentication cookie vs session cookie
    By Joseph in forum ASP.NET Security
    Replies: 4
    Last Post: August 12th, 10:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139