Page 1 of 1
Cookies in folders...
Posted: Fri Dec 15, 2006 5:15 am
by ojeffery
Hi all,
I've set a cookie, which is working fine, but it's only accessable from the folder of the page I set it in (in this case the admin folder). I didn't specifically tell it to set in that folder, but it only works on files in there. I need to be able to access it from all folders in the site. What am I doing wrong?
Cheers, Oli.
Posted: Fri Dec 15, 2006 6:00 am
by Rovas
Read the PHP manual: $_SERVER['DOCUMENT_ROOT'] and use it in the code to indicate from where (the admin folder) to read the cookie. You must check the user rights for that folder. You might change to session and create a special directory for the sessions.
Posted: Fri Dec 15, 2006 6:19 am
by ojeffery
Thanks, but I still can't get it to work. I've set the cookie as follows:
Code: Select all
setcookie ("id", $get_info[0], 0, '/');
It's set in a file called
login.php within the
/admin folder.
I've set up a test page to find out if the cookie has worked properly, which just picks up the cookie and prints it. I've installed it with the same code in the
/admin folder and the root folder, and it only works in the former.
The code for
test.php is as follows. Is there perhaps another way of accessing it?
Code: Select all
<?php
$id=$_COOKIE['id'];
print "$id";
?>
Posted: Fri Dec 15, 2006 8:54 am
by Rovas
You can retrieve information from the directory using fopen or get_content
Code: Select all
$path=$_SERVER['DOCUMENT_ROOT'] ."/admin/cookie.txt" ;
fopen($path, "r");
//or
obj=get_content ($path);
I suggest you read the comments on this page:
http://php.net/fopen
Posted: Fri Dec 15, 2006 9:00 am
by feyd
Cookie information isn't stored on the server.