Jump to content

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
Link to comment
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
Link to comment
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.

Link to comment
Share on other sites

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.   Paste as plain text instead

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