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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    156
    Thanks
    8
    Thanked 1 Time in 1 Post

    cookie - folder based

    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

  • #2
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    I'm not sure exactly what your asking for. Something like this perhaps?

    PHP Code:

    $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



  • #3
    Regular Coder
    Join Date
    Mar 2005
    Posts
    156
    Thanks
    8
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Element View Post
    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:
    PHP Code:
    <?
    $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:
    PHP Code:
    $current_folder basename(dirname(__FILE__));

    if (isset(
    $_COOKIE[$current_folder])) {
      
     echo(
    "yes");

    } else {

      echo(
    "no");



    ?> 
    Thanks
    Last edited by ziggy1621; 07-05-2007 at 04:20 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
    •