Jump to content

[SOLVED] include "page1.php" if cant find "page2.php"


farkewie

Recommended Posts

Hi im trying to trap errors in my include statments here is y code but it is not working.

 

 


<?php 	     

if (isset($page)){

	include ("$dir/$page.php");

	if (!include("$dir/$page.php")) {

		include ("$dir/main.php");
	}
}
else {

	include ("$dir/main.php");
}
?>

edit: ^^ works same with less code  :P

 

file_exists() is what you want

 

<?php 	     
if(isset($page))
{
if(file_exists($dir ."/". $page .".php"))
{
	include ($dir ."/". $page .".php");
}
else
{
	include($dir."/main.php");
}
}
else
{
include ($dir."/main.php");
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.