...

View Full Version : Cookies are set, but wont display on page



lansing
05-05-2006, 12:21 AM
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
if(isset($_COOKIE['refid']))
{
$user_id = $_COOKIE['refid'];
echo '$user_id';
echo $_COOKIE['refid'];
}
else
{
echo 'No Referral for you';
}
?>

degsy
05-05-2006, 04:01 PM
Try this and see why you get


<?php
if(isset($_COOKIE['refid'])){
foreach($_COOKIE as $key => $val){
echo "$key: $val<br>";
}
}
else{
echo 'No Referral for you';
}
?>

lansing
05-05-2006, 04:08 PM
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
if(isset($_GET['id']))
{
$referral_id = $_GET['id'];
setcookie("refid", $referral_id, time()+2592000); //Lasts for 30 Days
setcookie("ref", $referral_id, time()+2592000, '/', 'domainname.com');
}
?>



<?php
$user_id = $_COOKIE['ref'];
echo $user_id;
?>

lansing
05-05-2006, 04:16 PM
Try this and see why you get


<?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.

degsy
05-05-2006, 04:18 PM
As a test, change 'domainname.com' to '.domainname.com'

Also, just use


<?php
foreach($_COOKIE as $key => $val){
echo "$key: $val<br>";
}
?>

just to see what cookies you have

degsy
05-05-2006, 04:19 PM
Also, remember that you have to refresh the page after setting a cookie.
Don't set it then immediately try to echo it.

lansing
05-05-2006, 04:37 PM
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
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum