Jump to content
Sign in to follow this  
Nicholas

Php Navigation

Recommended Posts

1st -

PHP Tutorials [Easy PHP Nav,the i-frame of the future or something]

 

 

 

OK first I'm going to show you the code,ready?

------------

<?php

switch($id) {

default:

include('main.htm');

break; case "blah":

include('blah1.htm');

break; case "blah2":

include(blah2.htm');

break; case "blah3":

include('blah3.htm');

break; case "blah4":

include('blah4.htm');

break; case "blah5":

include('blah5.htm');

}

?>

----------------------

-DEMO-

 

TOTALCHOICEHOSTING DOES SUPPORT PHP

 

The Steps:

------------

- The first thing you need to do is copy this file for the php coding (don't copy that coding above).

- Now if your confused maybe about the coding itself let me break it down

----------

<?php

switch($id) {

default:

include('main.htm'); ---put the url for ur newspro or something

break; case "blah": ----put the name u want the page to be an same for the rest

include('blah1.htm'); ----put the url for another page an same for the rest

break; case "blah2":

include(blah2.htm');

break; case "blah3":

include('blah3.htm');

break; case "blah4":

include('blah4.htm');

break; case "blah5":

include('blah5.htm');

}

?>

----------

Now you can of course make this longer by just adding this at the end an for common sense sake put it after:

-------------------

break; case "blah5":

include('blah5.htm');

---------------------

and for common sense sake put it above:

-----

}

?>

----

- OK now that u have the code u need to insert it where u would put your news or like if u had an i-frame replace the i-frame code the the php coding ,then save the page an name it yourpage.php

- Got that?..ok now for your links put this as the link "?id=default" now the name must correspond with your coding

ex: if

--------------------

break; case "blah":

include('blah1.htm');

--------------------

for the link it would be <a href="?id=blah">blah</a> and it would take u to the blah1.htm page.

- Now you just need to upload yourpage.php

-On to the next one, which is what I use and really simple

2nd

This is another method of doing this, which I think is pretty cool. But I'm running out of time so i won't elaborate much...

 

 

<?php

if (! file_exists("$page.php"))

{

include("404.php");

}

else

{

include("$page.php");

}

?>

 

Now that goes in your main page where you want the content to show up. Lets say you pasted it into index2.php. You need to make a 404.php and upload it in the same directory. Now you make the links to:

 

index2.php?page=whatever

 

and if for some reason one doesn't show up it'll revert to the 404 page. If you need help I'll try my best to help.

Edited by Nicholas

Share this post


Link to post
Share on other sites

Good tutorial, Nicholas, but I have to throw in my 2 cents and warn that your first method is MUCH safer and secure than the second. I would advise folks to avoid the second version.

 

The second option given trusts the input of the user. Even though you check for the existence of the file first, you open up the possiblity of including files you really don't want included. If you have any doubts, do a search on php security.

 

Also, the code, as written, only will work with register_globals on... which is the case here at TCH. But to make the code more transportable, clean, and safe, better to use the super globals like this:

 

$pageId = $_GET['id'];

switch($pageId) { ...rest of code

 

Another way to make all of this even more secure would be to have a single directory where all your include files reside and hard code that into your programming logic:

 

$base = $_SERVER['DOCUMENT_ROOT'].'/path/to/include/dir/';

$pageId = $_GET['id'];

switch($pageId) {

case 'home':

$extra = 'home_page.php';

...rest of switch logic

...

}//end of switch logic

@(include($base.$extra)) or die("File include failed");

 

The @ eliminates giving away the root directory of your website if your logic fails because you changed a file name, or something else goofed. Instead of the typical error message, revealing info you want kept private, the die statement kicks in and gives you the information you need to debug.

 

Anyone who has seen my other posts knows I'm only adding this to help. I'm certainly not trying to take away from Nicholas' generous donation of his knowledge.

Edited by surefire

Share this post


Link to post
Share on other sites

Hmm,.. ok i got lost right about here.

 

 

- OK now that u have the code u need to insert it where u would put your news or like if u had an i-frame replace the i-frame code the the php coding ,then save the page an name it yourpage.php

- Got that?..ok now for your links put this as the link "?id=default" now the name must correspond with your coding

ex: if

--------------------

break; case "blah":

include('blah1.htm');

--------------------

for the link it would be <a href="?id=blah">blah</a> and it would take u to the blah1.htm page.

- Now you just need to upload yourpage.php

-On to the next one, which is what I use and really simple

2nd

 

 

 

Okay,. I'm looking at my FP at the codes tab and this is what i got for the testpage and i used my site of course but anyway here it is.

 

<html>

 

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>testpage001</title>

</head>

 

<body>

 

<p align="center"><?php

switch($id) {

default:

include('http://www.onlineautorama.com/body.htm');

break; case "Home":

include('http://www.onlineautorama.com/forum/');

break; case "Forums":

include(http://www.onlineautorama.com/chat/');

break; case "Chat.":

include('http://www.onlineautorama.com/gallery');

break; case "Gallery":

include('http://www.onlineautorama.com/memberweb/');

break; case "Member Sites":

}

?></p>

 

</body>

 

</html>

 

Okay,.... Now you say

 

Got that?..ok now for your links put this as the link "?id=default" now the name must correspond with your coding

ex: if

--------------------

break; case "blah":

include('blah1.htm');

--------------------

for the link it would be <a href="?id=blah">blah</a> and it would take u to the blah1.htm page.

 

 

Where do i put my

<a href="?id=Home">http://www.onlineautorama.com/body.htm</a> at?

 

I believe your calling this "?id=default" the "link" does this go in the code somewhere? how do i get this code to work with the button icons going to be used on the site? or did i miss something all together here?

 

Thank you.

Share this post


Link to post
Share on other sites

This is not correct

include('http://www.onlineautorama.com/body.htm');

 

You want

include $_SERVER['DOCUMENT_ROOT'].'/body.htm';

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×