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"); } ?> Link to comment https://forums.phpfreaks.com/topic/76336-solved-include-page1php-if-cant-find-page2php/ 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"); } ?> Link to comment https://forums.phpfreaks.com/topic/76336-solved-include-page1php-if-cant-find-page2php/#findComment-386475 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"); } ?> Link to comment https://forums.phpfreaks.com/topic/76336-solved-include-page1php-if-cant-find-page2php/#findComment-386476 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. Link to comment https://forums.phpfreaks.com/topic/76336-solved-include-page1php-if-cant-find-page2php/#findComment-386483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.