cookies in different pages

Discussion in 'PHP' started by promotingspace.net, Mar 18, 2008.

  1. #1
    Hi
    I am wondering why my cookie is not working in another page.
    please check if there is a problem:
    first page: refer.php:
    link: http://sp724.com/members/refer.php?user=1
    code:
    <?php
    
    		if(isset($_GET['user']) AND is_numeric($_GET['user']) ) {
      $userid=$_GET['user'];		
      $in1Month1 = 60 * 60 * 24 * 30 + time(); 
      setcookie('refferer', $userid, $in1Months); 
    if(isset($_COOKIE['refferer'])){
    	$referer = $_COOKIE['refferer'];
    	echo $referer;
    	}
    } 
    //header("Location: http://rooyekhat4u.com");
    ?>
    PHP:
    2nd page:
    link: http://www.sp724.com/members/saleconfirmed.php
    code:
    <?php
    	if(isset($_COOKIE['refferer'])){
    	$referer = $_COOKIE['refferer'];
    	echo $referer;
    	}
    
    ?>
    PHP:
    but the first result is different with the second one
     
    promotingspace.net, Mar 18, 2008 IP
  2. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #2
    As far as I know script cannot access cookies set in the same script.
    So this code
    
     setcookie('refferer', $userid, $in1Months); 
    
    if(isset($_COOKIE['refferer'])){
        $referer = $_COOKIE['refferer'];
        echo $referer;
        }
    
    PHP:
    will not get you value of $_COOKIE['refferer'] you have set by setcookie in line before.
     
    AsHinE, Mar 19, 2008 IP