Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Quick PHP Cookies question

  • 09-12-2004 05: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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    http://ie2.php.net/setcookie

    Doublecheck the syntax of your usage of setCookie();


  • Registered Users, Registered Users 2 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