Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 32

Thread: Validating users

  1. #21
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Ok, the next test to do then is to echo $fulldir. Then we can see what the path looks like:

    PHP Code:
    <?php
    $fulldir 
    dirname(__FILE__);

    echo 
    $fulldir;
    ?>

  2. #22
    Join Date
    Dec 2010
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    C:\xampp\htdocs\phpmysimplelogin\sam

  3. #23
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    PHP Code:
    <?php

    $fulldir 
    'C:\xampp\htdocs\phpmysimplelogin\sam';

    // Get the deepest directory
    $dir substr(strrchr($fulldir'\\'), 1);

    echo 
    $dir;

    ?>
    That should output 'sam', are you sure it's not working?

  4. #24
    Join Date
    Dec 2010
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    yes that works now although when i put the two together it seems to now work and only displays one "sam"

  5. #25
    Join Date
    Dec 2010
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Code:
    // Inialize session
    session_start();
    
    // Check, if username session is NOT set then this page will jump to login page
    if (!isset($_SESSION['username'])) {
        header('Location: index.php');
    }
    
    // Get the directory we're currently in
    $fulldir = dirname(__FILE__);
    
    // Get the deepest directory
    $dir = substr(strrchr($fulldir, '\\'), 1);
    
    echo $_SESSION['username'];
    echo $dir;
    
    ?>
    this works ! it shows sam sam . but when i put this code into it

    Code:
    if(is_dir($dir) && $dir == $_SESSION['username']) {
        echo "ok";
    }
    else {
        echo "not ok";
    }
    it only displays not ok either looking at the same dir or not ?

  6. #26
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Ok, looks like there may be a space in one of the variables, try trimming the variables:

    PHP Code:
    <?php

    // Inialize session
    session_start();

    // Check, if username session is NOT set then this page will jump to login page
    if (!isset($_SESSION['username'])) {
        
    header('Location: index.php');
    }

    // Get the directory we're currently in
    $fulldir dirname(__FILE__);

    // Get the deepest directory
    $dir substr(strrchr($fulldir'\\'), 1);

    // Trim off any excess whitespace
    $username trim($_SESSION['username']);
    $dir trim($dir);

    if(
    is_dir($dir) && $dir == $username) {
        echo 
    "ok";
    }
    else {
        echo 
    "not ok";
    }

    ?>
    That should work. Let me know how it goes.

  7. #27
    Join Date
    Dec 2010
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Nope still im getting "not ok".

    this is what im doing :
    updating code
    saving it and copying it to the two different directories
    logging on using one username and being diverted to the first index.php file in their own directory
    then im going to the address bar and changing the name of the current dir to another users, im my case tom
    http://localhost:8000/phpmysimplelogin/sam/ the sam changes to tom
    the pages load but both still have "not ok" displayed in both ?

  8. #28
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Ahh just realised the mistake, it's looking at the wrong thing, try:

    PHP Code:
    <?php

    // Inialize session
    session_start();

    // Check, if username session is NOT set then this page will jump to login page
    if (!isset($_SESSION['username'])) {
        
    header('Location: index.php');
    }

    // Get the directory we're currently in
    $fulldir dirname(__FILE__);

    // Get the deepest directory
    $dir substr(strrchr($fulldir'\\'), 1);

    // Trim off any excess whitespace
    $username trim($_SESSION['username']);
    $dir trim($dir);

    if(
    is_dir($fulldir) && $dir == $username) {
        echo 
    "ok";
    }
    else {
        echo 
    "not ok";
    }

    ?>
    It's checking for "sam" relative to the current directory, instead of the full directory. Try the above and see what happens.

  9. The Following User Says Thank You to Schmoopy For This Useful Post:

    arsenalbates (12-28-2010)

  10. #29
    Join Date
    Dec 2010
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Smile

    WOOOOO , finally lol.

    that seems to have done the trick although its saying that its ok to be in the wrong directory and not ok to be in the right one .

    Thanks for your time and effort


  11. #30
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Hmm, strange, that should do the trick, double check the variables / path is all I can suggest.

Bookmarks

Posting Permissions

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