Turning variables into cookies?

Discussion in 'PHP' started by Seqqa, Nov 6, 2008.

  1. #1
    I have this script below and it give me a PHP error, anyone have a solution?

    <?php
    
    setcookie('{$_GET['r']}','blah',time()+86400); //expires in 1 day
    
    ?>
    PHP:
    + rep thanks!
     
    Seqqa, Nov 6, 2008 IP
  2. shineDarkly

    shineDarkly Banned

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    what error are you getting?

    anyways a quick glance on your code makes this stand out... please try to replace it with the code below

    setcookie($_GET['r'],'blah',time()+86400);
     
    shineDarkly, Nov 6, 2008 IP
    Seqqa likes this.
  3. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #3
    regarding a one small part of your script:

    '{$_GET['r']}'
    PHP:
    Above is wrong

    So, you can either use:
    setcookie($_GET['r'],'blah',time()+86400);
    PHP:
    or
    setcookie("{$_GET['r']}",'blah',time()+86400);
    PHP:
     
    ads2help, Nov 6, 2008 IP
    Seqqa likes this.
  4. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Simply use:
    
    <?php
    
    setcookie($_GET['r'],'blah',time()+86400); //expires in 1 day
    
    ?>
    
    PHP:
     
    elias_sorensen, Nov 6, 2008 IP
    Seqqa likes this.