file_exists() incorrectly reports false


#1

Hey,

I’ve got a thing going, ?page=index or ?page=whatever, and it checks to see if the file is there before including it. This worked when I was on my funpic server but now I’m on this new server and it just doesn’t! :evil: Current PHP version: 5.0.3.

What other information do I need to provide?

Things I’ve already tried:

  • Setting file permissions to read
  • In php.ini … safe_mode = Off
  • ini_set(‘safe_mode’, ‘Off’);

Here’s what I’ve been doing (forgive me if I’ve pasted anything irrelevant)…

[php]<?php
session_start();
require_once(“menu.php”);
$sidemenu = “”;
$bottommenu = “”;

$pagedir = "pages";
$datadir = "register";

foreach($links as $page => $text) {
	
	$serv1 = $_GET["page"];
	
	if (empty($serv1) || !file_exists($pagedir . "/" . $serv1 . ".htm")) {
		$serv1 = "home";
	}
	
	$sidemenu .= "n<a href="index.php?page={$page}"";
	if ($serv1 == $page) {
		$sidemenu .= " id="current"";
	}
	$sidemenu .= ">{$text}</a> ";
	
	$bottommenu .= "&middot; <a href="index.php?page={$page}"";
	if ($serv1 == $page) {
		$bottommenu .= " id="current2"";
	}
	$bottommenu .= ">{$text}</a>&nbsp;";
	
}
$bottommenu .= "&middot;";

$pageindex = $page = isset($_GET["page"]) ? $_GET["page"] : null;

if (!$page || $page == "home") {
	$page = "home.htm";
} else {
	$page = "{$page}.htm";
}

$serv2 = $page;

if (!file_exists($pagedir . "/" . $serv2)) {
	$page = "home.htm";
}

?>[/php]

In the body:

[php]<?php include_once($pagedir . "/" . $page); ?>[/php]

THIS IS MENU.PHP …

[php]<?php
$links = array();
//Format: $links[“page-name”] = “Link Text”;
//Will generate html that looks like Link Text
//the content will come from page-name.htm
$links[“home”] = “Home”;
$links[“upcoming”] = “Upcoming Symposiums”;
$links[“introd”] = “Introductions”;
$links[“moreinfo”] = “More Information”;
$links[“resrc”] = “Resources”;
$links[“media”] = “In the Media”;
$links[“contact”] = “Contact Information”;
?>[/php]


#2

Are you getting any errors? Use error_reporting(E_ALL); to get all errors.
Apart from that, what OS does the server run on? On Windows a backslash is required to indicate a folder path :wink:


#3

Should I use error_reporting(E_ALL); in the script itself, or php.ini? I’ll try it in the script.

It’s a Windows, so I’ll change it to a backslash - thank you!


#4

Didn’t work. I’ve changed “/” to “” where applicable and I’ve included error_reporting(E_ALL); - still no change. What now?

[php]<?php
session_start();

error_reporting(E_ALL);

require_once("menu.php");
$sidemenu = "";
$bottommenu = "";

$pagedir = "pages";
$datadir = "register";

foreach($links as $page => $text) {
	
	$serv1 = $_GET["page"];
	
	if (empty($serv1) || !file_exists($pagedir . "\" . $serv1 . ".htm")) {
		$serv1 = "home";
	}
	
	$sidemenu .= "n<a href="index.php?page={$page}"";
	if ($serv1 == $page) {
		$sidemenu .= " id="current"";
	}
	$sidemenu .= ">{$text}</a> ";
	
	$bottommenu .= "&middot; <a href="index.php?page={$page}"";
	if ($serv1 == $page) {
		$bottommenu .= " id="current2"";
	}
	$bottommenu .= ">{$text}</a>&nbsp;";
	
}
$bottommenu .= "&middot;";

$pageindex = $page = isset($_GET["page"]) ? $_GET["page"] : null;

if (!$page || $page == "home") {
	$page = "home.htm";
} else {
	$page = "{$page}.htm";
}

$serv2 = $page;

if (!file_exists($pagedir . "\" . $serv2)) {
	$page = "home.htm";
}

?>[/php]
[php]<?php include_once($pagedir . "\" . $page); ?>[/php]


#5

What happens when it runs?