PHP file_exists returns false with existing files

I have a little problem with my PHP code. I want to create a site with different directories. Each directory has a file named pass (not.txt or whatever) with a directory password value. Therefore, if the pass file does not exist, the group will not exist. But even if the group exists, it still says the group does not exist and I cannot open it either, but I can find 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 by the way. Thank you for your help!

+3


source to share


1 answer


I think this file must have an ending. eg..php or .html or whatever The filename '/groups/' . $group . '/pass';

is incorrect.

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



If it's a folder, it is sometimes discarded at the end. But it could be a file. When redirecting .htaccess

to index.html or index.php, there may be a slash at the end of the file.

0


source







All Articles