Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cookies are set, but wont display on page

    I have cookies set & can see them, but I am trying to echo the cookie data on the page. I have searched here & found many post. I am trying to display the the same way as other people, but is isn't working. I will post my code below. I get the No Referral for you text displayed every time.

    PHP Code:
    <?php
                
    if(isset($_COOKIE['refid']))
                {
                
    $user_id $_COOKIE['refid'];
                echo 
    '$user_id';
                echo 
    $_COOKIE['refid'];
                }
                else
                {
                echo 
    'No Referral for you';
                }
    ?>

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this and see why you get
    PHP Code:
    <?php 
    if(isset($_COOKIE['refid'])){ 
        foreach(
    $_COOKIE as $key => $val){
            echo 
    "$key: $val<br>";
        }

    else{ 
        echo 
    'No Referral for you'

    ?>

  • #3
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have been trying different ways to set the cookies & different browsers. I have the code to display the cookie data in index.php file. If I type in the URL domainname.com/foldername/index.php it says No Referral for you, but if I just type in the URL domainname.com/foldername it shows the cookie information.

    I then tried setting cookies as the code below & get the same results when typing the URL in the 2 different addresses above. When I type in the 2 different addresses in the URL & get the results I described I am using Firefox, but I can even get the cookie information to show in Internet Explorer not even when I type in the URL domainname.com/foldername.

    PHP Code:
    <?php 
        
    if(isset($_GET['id']))
            {
            
    $referral_id $_GET['id'];
            
    setcookie("refid"$referral_idtime()+2592000); //Lasts for 30 Days
            
    setcookie("ref"$referral_idtime()+2592000'/''domainname.com');
            }
    ?>
    PHP Code:
      <?php 
      $user_id 
    $_COOKIE['ref'];
      echo 
    $user_id
      
    ?>

  • #4
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by degsy
    Try this and see why you get
    PHP Code:
    <?php 
    if(isset($_COOKIE['refid'])){ 
        foreach(
    $_COOKIE as $key => $val){
            echo 
    "$key: $val<br>";
        }

    else{ 
        echo 
    'No Referral for you'

    ?>
    I posted the post above right after you did. I didn't see your reply before I type my post reply above...

    I did try that code you provided, but I am still getting the text No Referral for you. I have cookies set under 3 different names because I am trying different setcookie() coding. I changed the refid to match all 3 different names of cookies I have set & it wont display the data for none of the cookies.

  • #5
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As a test, change 'domainname.com' to '.domainname.com'

    Also, just use
    PHP Code:
    <?php  
        
    foreach($_COOKIE as $key => $val){ 
            echo 
    "$key: $val<br>"
        } 
    ?>
    just to see what cookies you have

  • #6
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Also, remember that you have to refresh the page after setting a cookie.
    Don't set it then immediately try to echo it.

  • #7
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by degsy
    Also, remember that you have to refresh the page after setting a cookie.
    Don't set it then immediately try to echo it.
    I was clicking the refresh button & it wouldn't display the cookie. I tried clicking the Home button & then going the site again & it displays the cookie data.

    I also changed the code to the
    PHP Code:
    <?php  
        
    foreach($_COOKIE as $key => $val){ 
            echo 
    "$key: $val<br>"
        }
    & the same results as the I describe below. The cookie data isn't displayed if I go the page by a link from another page, but cookie data will ONLY display if I go the page directly by typing in the URL the domain name/folder name/page name.php

    I have two steps below that says what I am doing to see the cookie data.
    In my foldername I have 2 pages. Index.php & page2.php....

    Step I
    I open a new window & type in the URL domainname.com/foldername/index.php ...the cookie data is displayed this way.

    Step II

    I then click on a link that is on the index.php page & it takes me to page2.php. On the page2.php I added the code you provided. It doesn't show the cookie data. If I type in the URL domain name/folder name/page2.php it will then show the cookie data
    Last edited by lansing; 05-05-2006 at 04:44 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •