It's not working because at the moment, you're assigning $filename to whatever the $_SESSION['username'] value is - so they're always going to be the same.
The $filename should be set by the actual directory, and not the session.
So you need to use:
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);
if(is_dir($dir) && $dir == $_SESSION['username']) {
echo "ok";
}
else {
echo "not ok";
}
?>
Depending on whether you're using windows or not, you may need to change this line:
PHP Code:
$dir = substr(strrchr($fulldir, '\\'), 1);
to
PHP Code:
$dir = substr(strrchr($fulldir, '/'), 1);
I'm using WAMP, so paths come out like: C:\wamp\www\DIR\DIR\file.php
Bookmarks