Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

TUTORIAL: PHP Navigation

Featured Replies

Hey guys :D Thought i'd make my php navigation into a small tut, as every website needs to contain a php navigation script, there are just so many.

 

Now, i know a lot of php navigations use switch. This means that the switch calls upon a case from a list of cases to switch between. This can save you a lot of files, as pages are kept lower. However, if you have a website that requires lots of pages, and you dont want to have to constantly update your navigation.php file or whatever, then take a look at this:

 

So, with all php, we need to start with our opening and closing tags:

<?php

?>

 

Right, now we need some variables in the code:

<?php

$folder = $_GET['folder'];
$page = $_GET['page'];

?>

This will use the $_GET method of receiving our folders and pages from the url.

 

Now we get to the if statements:

<?php

$folder = $_GET['folder'];
$page = $_GET['page'];

if (empty($page)) //if the page is empty
 {  
	include('home.php');  //include your default page
 }  

else  //otherwise,

 {  

include('error_page.php');  //include an error page, if the page cannot be found.

 };  

};  

?>

 

Now this is great, but it either displays home.php or error_page.php, it wont actually show any of our pages, so

 

This will now use the variables to get the folder and page:

<?php

$folder = $_GET['folder'];
$page = $_GET['page'];

if (empty($page)) //if the page is empty
 {  
	include('home.php');  //include your default page
 }  

else  //otherwise

 {  

if (file_exists($folder . '/' . $page . '.php'))  //if the folder and page exists

 {  

include($folder . '/' . $page . '.php');  //include that folder and page

 }  

else //otherwise

 {  

include('error_page.php');  //include an error page, if the page cannot be found.

 };  

};  
?>

 

Now all you need to do, is make your links look like this:

<a href="http://www.yoursite.com/index.php?folder=news&page=latest.php" alt="">Latest News</a> //i use & because its more valid than &

or something like that.

You could tie this in with a .htaccess file, so you have domain.com/folder/page

 

:p

I need to load up my lynda.com Cd's and learn some php.

  • Author

Yeah, if you DO decide to use .htaccess with my navigation, make sure you change all your links to:

<a href="http://www.yoursite.com/news/latest (.php is optional)" alt="">Latest News</a> //This ties in with .htaccess, so the $_GET won't get all screwed up

haha.

 

There is

 

icon11.gifBig Chief Ben

 

icon11.gifBaby Ben

and

 

icon11.gifThe Ben of the G.

haha.

 

There is

 

icon11.gifBig Chief Ben

 

icon11.gifBaby Ben

and

 

icon11.gifThe Ben of the G.

Ben G, da man :rolleyes:

  • Author

Stay on topic please ;)

your only saying that because its your topic :p

even though he has a point ;), I never user this kinda of navigation, I tend to keep as little files as possible, so most of the time I end up with a index file of at least 1500 lines of php or something :p

 

Wildo

  • Author

Thats the navigation i DID use. Depending on how my site is going to work, i might just use a switch navigation, and call functions from the function.php file.

Nice.

 

Can iask, how does google handle URLS like thios?

  • Author

Well you already seem to know how to use .htaccess so you should have no problem.

  • 10 months later...

whats a php navigation..?

You should run some sort of validation on those two variables.

What happens if someone enters the URL manually and places a (..) as the folder variable?

Then can get access to different folders... so of which you may not want.

 

Here's another suggestion from a tutorial site: http://www.tutorialtastic.co.uk/snippets/1

 

Sorry if it feels like I just took your topic. Security comes first in my eyes or at least I try to work at it as best as I can.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.