Jump to content

PHP Navigation help


Andy82

Recommended Posts

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

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

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

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.