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
Share on other sites

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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.