Reputation: 105
I have the following code snippet:
<?
include("/classes/functions.php");
if(!file_exists("/config.ini")) redirect("/classes/install.php");
else{
//file is processed
}
?>
What this is supposed to do is to read data from a configuration file then use it to connect to a MySQL server. If the configuration file doesn't exist, it redirects to a setup page where the file is created and filled with user-provided data.
Problem is, even though the file doesn't exist, file_exists
returns true anyway, which causes the else
branch to run and fail all over the place.
I tried using $_SERVER['DOCUMENT_ROOT']
in the file path, just in case; no difference.
Upvotes: 6
Views: 6344
Reputation: 521
Documentation: http://php.net/manual/en/function.file-exists.php
Returns TRUE if the file or directory specified by filename exists;
file_exists('/non-existing-file.ini') returns true because path '/' exists
use is_file() instead
Upvotes: 8
Reputation: 105
Found the source of the problem. For whoever might stumble upon this in the future, the Apache that comes with XAMPP doesn't execute PHP code if it's prefixed with <?
instead of <?php
.
Upvotes: 0
Reputation: 21
the probleme is in the redirect() function . there is no redirect in php use this code
<?
include("/classes/functions.php");
if(!file_exists("/config.ini")){
header("Location: /classes/install.php");
}else{
//file is processed
}
?>
Upvotes: -1