Cookies are driving me nuts!

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

    Cookies are driving me nuts!

    Hi.

    This is probably a newbie cookie problem:

    I got two files

    setcookie.php:

    <?
    setcookie("cook ie1","HELLO WORLD 1",time()+3600) ;
    setcookie("cook ie2","HELLO WORLD 2",time()+3600) ;
    ?>

    and showcookie.php:

    <?
    echo $_COOKIE["cookie1"]."<br>";
    echo $_COOKIE["cookie2"]."<br>";
    ?>

    The result of running setcookie.php and then showcookie.php is:

    Notice: Undefined index: cookie1 in C:\Apache
    Group\Apache2\h tdocs\showcooki e.php on line 5

    HELLO WORLD 2.


    In other words, only the last cookie has been set. What is wrong? This
    example is so simple, but yet I don't understand what is happening.

    I'm running PHP 4.2.2/Apache 2.0.39 on Win2000.

    Cheers

    Kasper


  • Pedro Graca

    #2
    Re: Cookies are driving me nuts!

    Kasper Kristensen wrote:[color=blue]
    > This is probably a newbie cookie problem:
    >
    > I got two files
    >
    > setcookie.php:[/color]

    1 <?
    2 setcookie("cook ie1","HELLO WORLD 1",time()+3600) ;
    3 setcookie("cook ie2","HELLO WORLD 2",time()+3600) ;
    4 ?>
    [color=blue]
    > and showcookie.php:[/color]

    1 <?
    2 echo $_COOKIE["cookie1"]."<br>";
    3 echo $_COOKIE["cookie2"]."<br>";
    4 ?>
    [color=blue]
    > The result of running setcookie.php and then showcookie.php is:
    >
    > Notice: Undefined index: cookie1 in C:\Apache
    > Group\Apache2\h tdocs\showcooki e.php on line 5[/color]

    line 5? ???

    These scripts work for me as you've posted them.
    I guess the error may be hidden on one of the lines you didn't post.

    Turn on error_reporting for all errors in your scripts (at least while
    debugging) by putting at the very top of them

    <?php error_reporting (E_ALL); ?>

    This is line 1, right before your opening <?php or <html> or whatever.
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • Kasper Kristensen

      #3
      Re: Cookies are driving me nuts!


      "Pedro Graca" <hexkid@hotpop. com> wrote in message
      news:c2tlk1$21i nho$1@ID-203069.news.uni-berlin.de...[color=blue][color=green]
      >> These scripts work for me as you've posted them.[/color]
      > I guess the error may be hidden on one of the lines you didn't post.
      >[/color]

      These are the only lines. I'm suspecting some kind og setup problem. Maybe
      in httpd.config er php.ini.
      [color=blue]
      > Turn on error_reporting for all errors in your scripts (at least while
      > debugging) by putting at the very top of them
      >
      > <?php error_reporting (E_ALL); ?>
      >[/color]

      I'll try that, and get back to you.

      Cheers
      Kasper


      Comment

      • Kasper Kristensen

        #4
        Re: Cookies are driving me nuts!


        "Kasper Kristensen" <nospam@nospam. invalid> wrote in message
        news:40525e70$0 $236$edfadb0f@d read12.news.tel e.dk...[color=blue]
        >
        > "Pedro Graca" <hexkid@hotpop. com> wrote in message
        > news:c2tlk1$21i nho$1@ID-203069.news.uni-berlin.de...[color=green][color=darkred]
        > >> These scripts work for me as you've posted them.[/color]
        > > I guess the error may be hidden on one of the lines you didn't post.
        > >[/color]
        >
        > These are the only lines. I'm suspecting some kind og setup problem. Maybe
        > in httpd.config er php.ini.
        >[color=green]
        > > Turn on error_reporting for all errors in your scripts (at least while
        > > debugging) by putting at the very top of them
        > >
        > > <?php error_reporting (E_ALL); ?>
        > >[/color]
        >
        > I'll try that, and get back to you.
        >
        > Cheers
        > Kasper
        >
        >[/color]

        Nope. Didn't explain a thing.

        Kasper


        Comment

        • Peter Taurins

          #5
          Re: Cookies are driving me nuts!

          Try making sure you have no spaces or carriage returns anywhere after line
          4.


          "Kasper Kristensen" <nospam@nospam. invalid> wrote in message
          news:405262a3$0 $253$edfadb0f@d read12.news.tel e.dk...[color=blue]
          >
          > "Kasper Kristensen" <nospam@nospam. invalid> wrote in message
          > news:40525e70$0 $236$edfadb0f@d read12.news.tel e.dk...[color=green]
          > >
          > > "Pedro Graca" <hexkid@hotpop. com> wrote in message
          > > news:c2tlk1$21i nho$1@ID-203069.news.uni-berlin.de...[color=darkred]
          > > >> These scripts work for me as you've posted them.
          > > > I guess the error may be hidden on one of the lines you didn't post.
          > > >[/color]
          > >
          > > These are the only lines. I'm suspecting some kind og setup problem.[/color][/color]
          Maybe[color=blue][color=green]
          > > in httpd.config er php.ini.
          > >[color=darkred]
          > > > Turn on error_reporting for all errors in your scripts (at least while
          > > > debugging) by putting at the very top of them
          > > >
          > > > <?php error_reporting (E_ALL); ?>
          > > >[/color]
          > >
          > > I'll try that, and get back to you.
          > >
          > > Cheers
          > > Kasper
          > >
          > >[/color]
          >
          > Nope. Didn't explain a thing.
          >
          > Kasper
          >
          >[/color]


          Comment

          • Reply Via Newsgroup

            #6
            Re: Cookies are driving me nuts!

            Kasper Kristensen wrote:
            [color=blue]
            > "Kasper Kristensen" <nospam@nospam. invalid> wrote in message
            > news:40525e70$0 $236$edfadb0f@d read12.news.tel e.dk...
            >[color=green]
            >>"Pedro Graca" <hexkid@hotpop. com> wrote in message
            >>news:c2tlk1$2 1inho$1@ID-203069.news.uni-berlin.de...
            >>[color=darkred]
            >>>>These scripts work for me as you've posted them.
            >>>
            >>>I guess the error may be hidden on one of the lines you didn't post.
            >>>[/color]
            >>
            >>These are the only lines. I'm suspecting some kind og setup problem. Maybe
            >>in httpd.config er php.ini.
            >>
            >>[color=darkred]
            >>>Turn on error_reporting for all errors in your scripts (at least while
            >>>debugging) by putting at the very top of them
            >>>
            >>><?php error_reporting (E_ALL); ?>
            >>>[/color]
            >>I'll try that, and get back to you.
            >>
            >>Cheers
            >>Kasper
            >>
            >>[/color]
            >
            >
            > Nope. Didn't explain a thing.
            >
            > Kasper
            >
            >[/color]

            It looks like you are making the assumption that the first cookie is not
            set - It just seems to have problems displaying it - I don't know why
            (it works fine on my system) but what you could do is change your
            showcookie.php script to what I have below - Alternatively, just change
            showcookie.php to have a single command: phpinfo(); This command dumps
            the full php environment out in a nice table so you should be able to
            page down (or do a find on the page) for COOKIE1 and COOKIE2.

            If you still have problems, just humour me and choose different names
            for the cookies - Call COOKIE1 abc and call COOKIE2 def - It could be
            that somehow, COOKIE1 is a reserved word and that cannot be used as an
            index on your system.... I'm just pulling at straws here mind...


            anyway... My suggested showcookie.php:

            <?
            foreach($_COOKI E as $cookieName=>$c ookieValue)
            { print("<br>Cook ie named $cookieName has value $cookieValue");
            }
            ?>


            Drop another byte if you still have problems...

            randelld

            Comment

            • Kasper Kristensen

              #7
              Re: Cookies are driving me nuts!


              "Peter Taurins" <DONOTEMAILMEOH SPAMMEISTERSpet er.taurins@bigp ond.com> wrote
              in message news:AYu4c.1010 35$Wa.32027@new s-server.bigpond. net.au...[color=blue]
              > Try making sure you have no spaces or carriage returns anywhere after line
              > 4.
              >
              >[/color]

              No, that wasn't it. I also guess that this would result in the "header
              already sent" error.

              Kasper


              Comment

              • Kasper Kristensen

                #8
                Re: Cookies are driving me nuts!


                "Reply Via Newsgroup" <reply-to-newsgroup@pleas e.com> wrote in message
                news:U3x4c.7895 83$X%5.225024@p d7tw2no...[color=blue]
                > It looks like you are making the assumption that the first cookie is not
                > set - It just seems to have problems displaying it - I don't know why
                > (it works fine on my system) but what you could do is change your
                > showcookie.php script to what I have below - Alternatively, just change
                > showcookie.php to have a single command: phpinfo(); This command dumps
                > the full php environment out in a nice table so you should be able to
                > page down (or do a find on the page) for COOKIE1 and COOKIE2.
                >[/color]

                Yep already tried that. "cookie1" is not set. Actually if I extend it to
                "cookie1","cook ie2"..."cookieN " only "cookieN" gets set.

                [color=blue]
                > If you still have problems, just humour me and choose different names
                > for the cookies - Call COOKIE1 abc and call COOKIE2 def - It could be
                > that somehow, COOKIE1 is a reserved word and that cannot be used as an
                > index on your system.... I'm just pulling at straws here mind...
                >
                >[/color]

                No doesn't work work either. The last cookie is the only one that is set.

                Cheers
                Kasper


                Comment

                • Kasper Kristensen

                  #9
                  Re: Cookies are driving me nuts!

                  [color=blue]
                  > No doesn't work work either. The last cookie is the only one that is set.
                  >
                  > Cheers
                  > Kasper
                  >
                  >[/color]

                  Just found at that it works under PHP4.3.4, which my web hotel runs, so I'll
                  try to upgrade.

                  Thanks for your suggestions.


                  Kasper


                  Comment

                  Working...