ev5unleash Posted August 15, 2008 Share Posted August 15, 2008 Hi I have this code. <?php include('./top.html'); // header switch(strtolower($_GET['id'])) // 'content' { case "contact": include("contact.html"); break; case "smartboardsolution": include("smartboardsolution.html"); break; case "error=404": include("ermes/404.html"); break; case "error=403": include("ermes/403.html"); break; case "redirect": include("redirect.html"); break; default: include("home.php"); break; } include('./bottom.html'); // footer ?> Instead of giving my users a weird php error page I would like to display my own message, page or 404. Link to comment https://forums.phpfreaks.com/topic/119761-php-include-if-not-correct-then-404-or-selected-page/ Share on other sites More sharing options...
chronister Posted August 15, 2008 Share Posted August 15, 2008 Since you are ultimately trying to load a file, simply add the code to see if file exists. <?php include('./top.html'); // header switch(strtolower($_GET['id'])) // 'content' { case "contact": if(is_file('/path/to/contact.html')) { include("contact.html"); } else { // not a file, so show the custom message or 404 error. } break; case "smartboardsolution": include("smartboardsolution.html"); break; case "error=404": include("ermes/404.html"); break; case "error=403": include("ermes/403.html"); break; case "redirect": include("redirect.html"); break; default: include("home.php"); break; } include('./bottom.html'); // footer ?> I only added the code to the first case, you can even restructure it a bit so it only runs once instead of running in each case. Nate Link to comment https://forums.phpfreaks.com/topic/119761-php-include-if-not-correct-then-404-or-selected-page/#findComment-617121 Share on other sites More sharing options...
ev5unleash Posted August 15, 2008 Author Share Posted August 15, 2008 Thanks! Link to comment https://forums.phpfreaks.com/topic/119761-php-include-if-not-correct-then-404-or-selected-page/#findComment-617365 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.