Web Analytics Made Easy -
StatCounter cookies - CodingForum

Announcement

Collapse
No announcement yet.

cookies

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • cookies

    Hey,

    I am having trouble storing a cookie on my machine. I am running php verion 5.1.1 and I have used firefox and IE to try and set cookies. Both browsers are set to accept cookies but neither do. Do I need to alter php_info() in some way or any .config files to ge my cookies to store?

    Thanks

  • #2
    What is the code you have currently for storing the cookies?
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

    Comment


    • #3
      Remember the $_COOKIES global variable does not get set until control has gone back to the browser and then the page is requested again, because it's actually the browser that saves the cookie. I didn't really phrase that well-- read the "common pitfalls" section in setcookies page of the manual.

      Comment


      • #4
        Simple code like this doesnt return a value when the cookie is recalled which lead me to believe its a problem with some of my settings.


        PHP Code:
        COOKIES.PHP

        <?php
        $value 
        "my cookie value";

        // send a cookie that expires in 24 hours
        setcookie("TestCookie",$valuetime()+3600*24);

        ?>

        COOKIESRET.PHP

        <?php


        // Print individual cookies
        echo $_COOKIE["TestCookie"];

        ?>

        Comment


        • #5
          Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/content/*/*/*/****/html/jay/****/setcookie.php on line 2

          Parse error: parse error, unexpected T_STRING in /home/content/*/*/*/****/html/jay/****/setcookie.php on line 2

          Comment


          • #6
            rafiki, was that error generated when you run that script? what does it mean?

            Comment


            • #7
              yes it was i dont no wat it means lol, scondly i realized that your echo was NOT in the quotes like echo " $_COOKIE['TestCookie']"; also im not sure if u can echo a cookie :S

              Comment


              • #8
                Originally posted by rafiki View Post
                yes it was i dont no wat it means lol, scondly i realized that your echo was NOT in the quotes like echo " $_COOKIE['TestCookie']"; also im not sure if u can echo a cookie :S
                printing variables quotes are not necessary and every variable can be printed or echoed.
                Free php image upload script
                Personal web developing blog

                Comment


                • #9
                  I placed
                  PHP Code:
                  <?php 
                  $value 
                  "my cookie value"

                  // send a cookie that expires in 24 hours 
                  setcookie("TestCookie",$valuetime()+3600*24); 

                  ?>
                  on a page named "cookies.php" and
                  PHP Code:
                  <?php 


                  // Print individual cookies 
                  echo $_COOKIE["TestCookie"]; 

                  ?>
                  on a page named "cookiesret.php".

                  I visited then visited them (in their respective order of "cookies.php" then "cookiesret.php") and everything worked fine.
                  PHP Code:
                  echo $_COOKIE["TestCookie"]; 
                  Echoed the value "my cookie value".
                  Not sure what could be wrong on your side....
                  Dawson Irvine
                  CEO - DNI Web Design
                  http://www.dniwebdesign.com

                  Comment

                  Working...
                  X