Andy82 Posted March 4, 2008 Share Posted March 4, 2008 Hey, Can someone please help with the code below. I am learning PHP and making a site solely for the purpose of learning but want a means of navigating from page to page. As a newbie I don’t really know if I am going in the right direction, is this the right way to do things? What I have so far is below. What I need the code to do... Default to modules/news/index.php if no variables are set. If only a folder is set show the index.php file of that folder. If only the file is set show modules/filename.php If the folder or file is not found then show an error page. Current it appears to work correctly, apart from showing the error page and just shows the PHP warnings… Warning: main(modules/xxxxx/xxxx.php) [function.main]: failed to open stream: No such file or directory in /xxxxx/xxxxx/xxxxx/xxxxx on line 2 <?php $folder = $_GET['go']; $file = $_GET['to']; if(!isset($folder) && (!isset($file))) { include"modules/news/index.php"; } elseif(isset($folder) && isset($file)) { include "modules/".$folder."/".$file.".php"; } elseif (!isset($folder) && isset($file)) { include "modules/".$file.".php"; } elseif (!isset($file) && isset($folder)) { include "modules/".$folder."/index.php"; } else { include "modules/error/404.php"; } ?> Thank you for any help you can provide. Andy Link to comment https://forums.phpfreaks.com/topic/94301-php-navigation-help/ Share on other sites More sharing options...
bpops Posted March 4, 2008 Share Posted March 4, 2008 Your erroris exactly as it says: the file you are specifying does not show up. Since you replaced the folder/file names with xxxx's, I don't know specifically which one it's not finding (or even if it's in this code). Link to comment https://forums.phpfreaks.com/topic/94301-php-navigation-help/#findComment-483009 Share on other sites More sharing options...
Andy82 Posted March 4, 2008 Author Share Posted March 4, 2008 Hey, Thank you for replying. I know the folder doesn’t exist…but instead of showing the error I want it to show my error page (modules/error/404.php). I have read that default 404 page can be replaced using .htaccess but as the site is set up as header, content (the code from my first post is in here.) and footer files included in the index file I thought I needed to do it this way. Andy Link to comment https://forums.phpfreaks.com/topic/94301-php-navigation-help/#findComment-483026 Share on other sites More sharing options...
Andy82 Posted March 6, 2008 Author Share Posted March 6, 2008 Hey, I'm still trying to get this to work (without any luck ) Could someone please shed so light on this I have tried checking if the files exist, if not show the custom error page, again without luck. Basically I want it so if the folder or file requested doesn't exists it shows the (modules/error/404.php). Thank you Andy Link to comment https://forums.phpfreaks.com/topic/94301-php-navigation-help/#findComment-484760 Share on other sites More sharing options...
Andy82 Posted March 6, 2008 Author Share Posted March 6, 2008 Anyone know please. Link to comment https://forums.phpfreaks.com/topic/94301-php-navigation-help/#findComment-485112 Share on other sites More sharing options...
cooldude832 Posted March 6, 2008 Share Posted March 6, 2008 you can do this <?php $file = $_GET['file']; if(!is_file($file)){ $file = "404.php"; } include($file); ?> Very basic idea Link to comment https://forums.phpfreaks.com/topic/94301-php-navigation-help/#findComment-485115 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.