PHP Session or Cookie help

Discussion in 'PHP' started by EatingEmoKids, Jan 16, 2011.

  1. #1
    Hi, I'm looking to store some information when some one is traveling around on my site and I'm not sure how I would do this. Basically if some one comes to my site from a link like this:

    http://www.mysite.com/link.php?id=001
    Code (markup):
    My site would keep track of the number "001" and I'd be able to grab this number and display it in specific pages of the website.

    I'd appreciate any help.

    Thanks!
     
    EatingEmoKids, Jan 16, 2011 IP
  2. langtusitinh225

    langtusitinh225 Greenhorn

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #2
    You can use $_SERVER['HTTP_REFERER']
     
    langtusitinh225, Jan 17, 2011 IP
  3. ssmm987

    ssmm987 Member

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    3
    Trophy Points:
    43
    #3
    Something like this?
    
    $_SESSION['id']=$_GET['id'];
    
    PHP:
     
    ssmm987, Jan 17, 2011 IP
  4. langtusitinh225

    langtusitinh225 Greenhorn

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    
    if ($_SERVER['HTTP_REFERER'])
    {
    	$link = $_SERVER['HTTP_REFERER'];
    	$link = explode('id=', $link);
    	$id = $link[1];
    }
    
    PHP:
     
    langtusitinh225, Jan 17, 2011 IP
  5. Litonice09

    Litonice09 Well-Known Member

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    111
    Digital Goods:
    1
    #5
    This the code below:

    <?
    session_start();
    session_register('count');
    $_SESSION[count]++;
    $msg = "<P>You've been here $_SESSION[count] times. Thanks!</p>";
    ?>
    <HTML>
    <HEAD>
    <TITLE>Count Me!</TITLE>
    </HEAD>
    <BODY>
    <? echo "$msg"; ?>
    </BODY>
    </HTML>


    Save the file with the name countme.php. Hope your problem solved.
     
    Litonice09, Jan 17, 2011 IP
  6. langtusitinh225

    langtusitinh225 Greenhorn

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #6
    I think you should replace

    
    <? echo "$msg"; ?>
    
    PHP:
    by

    
    <?=$msg?>
    
    PHP:
    It's shorter and clear
     
    langtusitinh225, Jan 17, 2011 IP
  7. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #7
    The short php tag is not enabled on all hosting environments (and sometimes can not be simply changed) - theirfore compatibility issues, furthermore rumours claim from PHP 6 short tags will be deprecated (see here).
     
    danx10, Jan 18, 2011 IP