PHP file_exists returns false with existing files

1k views Asked by At

I'm having a little problem with my PHP-code. I want to create a site which has different directories. Every directories has a file named pass (not .txt or something) with the value of the directories password. So if the pass-file doesn't exist the group will not exist. But even if the group exists it still says the group doesn't exist and I can't fopen the file either, but I can locate to it. Here's my code:

<?php
$name = $_POST['name'];
$group = $_POST['group'];
$pass = $_POST['pass'];
$filename = '/groups/' . $group . '/pass';
if(file_exists($filename)){
    $handle = fopen($filename) or die("can't open file");
    $hoi = fread($handle, filesize($filename));
    fclose($handle);
    if ($pass === $hoi){
        session_start();
        $_SESSION['name'] = $name;
        header('Location: http://www.google.com');
    }
    else{
        echo 'Password is wrong!';
    }
}
else{
    echo 'Group does not exist!';
}
?>

All POST-data is correct btw. Thanks for your help!

1

There are 1 answers

0
CZ workman On

I think, that file pass must have ending. eg. .php or .html or something File name '/groups/' . $group . '/pass'; is wrong.

PHP function is named file_exist() and files must have endings!

If it is folder it has sometimes slash at the end. But it can be file. With .htaccess redirect, on index.html or index.php could be slash at the end of the file.