• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 805
  • Last Modified:

PHP file_exists returns false for existing file, until REFRESH is performed

I am trying to debug code on an existing 3rd party website that makes use of file_exists() to determine which version of a homepage exists.

The code returns false the first time the page is invoked, thus showing the wrong version of the homepage. But after pressing REFRESH on the browser, it then finds the file.

I can only imagine that after the page is first displayed, some other setting is made dynamically which somehow enables the file_exists() functionality, or at least fixes it.

Any thoughts as to what might be behind this?
// TEST---------------------------------------------
	echo "TEST 1<br>";
	if (file_exists(JB_THEME_PATH.'index-home.php')) {
		echo "FILE: " . JB_THEME_PATH.'index-home.php' . " DOES EXIST<br>";
	} else {
		echo "FILE: " . JB_THEME_PATH.'index-home.php' . " DOES NOT EXIST<br>" . "USING FILE: " . JB_DEFAULT_THEME_PATH.'index-home.php' . " INSTEAD!";

Open in new window

  • 2
3 Solutions
Most likely on your form you have something like this
<form method=post action="<? $_SERVER['PHP_SELF']?>">
and you have your PHP code above your form at a guessing. Try having the PHP queries on another file and link to them instead of using the same page.
rascalAuthor Commented:
Thansk drakeshe,
I'll have a look at the code and see if that's the cause. This is 3rd party shrinkwrap software that's been around a while (Jamit job board) so I'm thinking their code on it's own is probably ok, and that perhaps it's a site setting of some kind(?), but I'll check it out.
I had the same problem myself. Probably the best way to get it to work is to get JavaScript to refresh the page again.
your code worked for me .... may a full script will  be easier ....

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now