farkewie Posted November 7, 2007 Share Posted November 7, 2007 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"); } ?> Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2007 Share Posted November 7, 2007 here you go <?php if (isset($page) && file_exists("$dir/$page.php")) { include ("$dir/$page.php"); } else { include ("$dir/main.php"); } ?> Quote Link to comment Share on other sites More sharing options...
Prismatic Posted November 7, 2007 Share Posted November 7, 2007 edit: ^^ works same with less code 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"); } ?> Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 7, 2007 Author Share Posted November 7, 2007 Thank you so much it works perfectly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.