...

View Full Version : cookie - folder based



ziggy1621
07-03-2007, 08:11 PM
I'm writing a script that creates a new folder when a user signs up. I want a cookie that allows them to only change their information (i.e. only the files in their folder).

Does anyone have a good tutorial of how to write the php code to say if cookie 'currentFolder' is available.... then i would include the admin/edit scripts.

Thanks in advance,
ziggy

Element
07-04-2007, 01:06 AM
I'm not sure exactly what your asking for. Something like this perhaps?




$server_path = 'home/user/public_html/';

// Some code to set the cookie

setcookie('currentFolder', 'test_folder', time() + (60*60*24) or die("Failed to set cookie! Please enable cookies on your browser.");

// End some code

if (isset($_COOKIE['currentFolder'])) {
if(file_exists($server_path . $_COOKIE['currentFolder'])) {
// Proceed with adding the edit material.

} else {
die("Unable to match up credentials.");
}
} else {
// Proceed with error or whatever upon finding NO current folder

}

ziggy1621
07-05-2007, 02:56 PM
I'm not sure exactly what your asking for. Something like this perhaps?



yeah, i did leave it a bit vague. When the user logs in, a cookie will be placed on their computer. Now, as they navigate the couple of pages they have access to in their folder, they will have admin/edit rights through a couple of other scripts I have put together.

So something to the effect of:
if the cookie is on their computer, require the edit scripts ONLY in this folder.

hope that is better,
thanks for the help

EDIT:

You got me thinking in the right direction... this is what I have:

Code included if authenticated:


<?
$current_folder = basename(dirname(__FILE__));

// Some code to set the cookie

setcookie($current_folder, 'test_folder', time() + (60*60*24));

// End some code

Code on top of each page in directory:


$current_folder = basename(dirname(__FILE__));

if (isset($_COOKIE[$current_folder])) {

echo("yes");

} else {

echo("no");

}

?>


Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum