Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Quick PHP Cookies question

Options
  • 09-12-2004 5:22pm
    #1
    Closed Accounts Posts: 72 ✭✭


    Hi im in the middle of learning php and im just doing cookies at the moment but i am getting a parse error and im not sure why. If anyone would mind taking a look for me cheers!
    This one works fine
    [php]
    <?php

    $myVal = "1093529642";

    setCookie('real.com',"$myVal", time() + 3600 * 24);

    ?>
    [/php]

    [php]
    <?php

    echo

    ?>
    [/php]
    Parse error: parse error, expecting '','' or '';'' in /home/ict/bgoldbach/public_html/p4/stu/des/p4ex802.php on line 3


    Oh by the way i am trying to get it ot print out the cookie real.com


Comments

  • Registered Users Posts: 1,169 ✭✭✭dangerman


    not a php expert by any means,

    but don't you need a ; after the

    echo

    line?

    sorry if this is just stoopid.


  • Closed Accounts Posts: 72 ✭✭not_sure


    dangerman thats the parse error its giving me


  • Registered Users Posts: 1,169 ✭✭✭dangerman


    ok, i think we better wait till one of the big kids gets here.

    /me runs off back to the photoshoppage forum.


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    http://ie2.php.net/setcookie

    Doublecheck the syntax of your usage of setCookie();


  • Registered Users Posts: 912 ✭✭✭chakotha


    Shouldn't it be

    [PHP]<?php

    echo($real.com);

    ?> [/PHP]

    You might have to drop the full stop in the variable name - not sure about that


  • Advertisement
  • Closed Accounts Posts: 35 Ivan Dunaev


    echo $_COOKIE;


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    First of all, a minor point, in that your variable $myVal need not be in quotes:
    [PHP]<?php
    setCookie("real.com", $myVal, time() + 3600 * 24);
    ?> [/PHP]
    Think of your cookie as an array and the above has just set the value $myVal to the array key "real.com". On your second and subsequent scripts you can then output the cookie:
    [PHP]<?php
    echo $_COOKIE["real.com"];
    ?> [/PHP]
    Other tricks you can try with arrays include checking if a cookie variable has been set:
    [PHP]<?php
    if (isset($_COOKIE["real.com"])) {
    echo "real.com is set";
    } else {
    echo "real.com is not set";
    }
    ?> [/PHP]
    And listing out all the cookie variables currently set (remember it is an array):
    [PHP]<?php
    foreach($_COOKIE as $key => $value) {
    echo $key." : ".$value;
    }
    ?> [/PHP]
    HTH


Advertisement