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;
?>
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;
?>
C:\xampp\htdocs\phpmysimplelogin\sam
That should output 'sam', are you sure it's not working?PHP Code:<?php
$fulldir = 'C:\xampp\htdocs\phpmysimplelogin\sam';
// Get the deepest directory
$dir = substr(strrchr($fulldir, '\\'), 1);
echo $dir;
?>
yes that works now although when i put the two together it seems to now work and only displays one "sam"
this works ! it shows sam sam . but when i put this code into itCode:// 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; ?>
it only displays not ok either looking at the same dir or not ?Code:if(is_dir($dir) && $dir == $_SESSION['username']) { echo "ok"; } else { echo "not ok"; }
Ok, looks like there may be a space in one of the variables, try trimming the variables:
That should work. Let me know how it goes.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";
}
?>
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 ?
Ahh just realised the mistake, it's looking at the wrong thing, try:
It's checking for "sam" relative to the current directory, instead of the full directory. Try the above and see what happens.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";
}
?>
arsenalbates (12-28-2010)
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
![]()
Hmm, strange, that should do the trick, double check the variables / path is all I can suggest.
Bookmarks