Jump to content


Photo
- - - - -

quick/easy/secure php dynamic links


  • Please log in to reply
7 replies to this topic

#1 ShadowDeath01

ShadowDeath01

    Young Padawan

  • Members
  • Pip
  • 71 posts

Posted 22 August 2006 - 11:05 PM

well i have seen php navigation out there a lot of it, but all the ones i have seen give away your php page names here is one that dosen't if you name then right. here we go

<?php
$page = $_GET['id'];
switch($page){
case '': //sets the default page this is two single quotes not one double quote
include("index.php"); //defines the default page that will be shown
break; //break in the script so you can start a new one

case 'staff': //sets the name that will be shown in the address bar when you click the "Staff" link.
include("about.php"); //sets the staff page notice it is different than the case so people don't know your page
break; //breaks the script so you can start a new case
} // closes the switch
?> // closes the script

Lets break it down:

<?php

Opens the php code block

$page = $_GET['id'];
defines the $page variable and tells the script to get the page name after the = sign in index.php?id=whatever

switch($page){
tells the script to switch the name of the file such as about.php with the case set in "case"

case '':
defines the name of the page put two single quotes (not one double quote) and leave it blank in between to set the default page or put something in such as "staff" to make your link to the about.php page index.php?id=staff

include("index.php");

includes the page that the name will be switched with the "case" in this case it won't be switched because the case'': was left blank so this would be your default page

break;

puts a break in the script so you can define new "case"s and "include"s.

}
this closes the "switch" function

?>

this closes the php code block

This concludes my tutorial on quick/easy/secure php dynamic navigation. Hope this helps you in your future php coding!!!
  • elfeitabench and nzbhnqldbt like this

#2 Indigo

Indigo

    Official Alien

  • Members
  • PipPipPip
  • 617 posts
  • Gender:Male
  • Location:Trondheim, Norway
  • Interests:Computing in general, especially design and programming of all kinds.

Posted 24 August 2006 - 02:10 AM

Instead of:
case '': //sets the default page this is two single quotes not one double quote
include("index.php"); //defines the default page that will be shown
break; //break in the script so you can start a new one

you could use:
default:
include("index.php"); //defines the default page that will be shown
break; //break in the script so you can start a new one

And when using these kind of links, your links should look like this:
<a href="?page=oneofthepagesintheswitch">Link to one of the pages</a>

Anyway, thanks for sharing, this might be useful for some :)
  • elfeitabench likes this

#3 ShadowDeath01

ShadowDeath01

    Young Padawan

  • Members
  • Pip
  • 71 posts

Posted 01 September 2006 - 10:15 PM

actually the links would be something like depending what page you put that in say it was index.php then the links would be
<a href="index.php?page=oneofthepagesintheswitch">Link</a>

guess i should have put that

#4 Jem

Jem

    Young Padawan

  • Members
  • Pip
  • 93 posts
  • Location:England
  • Interests:Photography, design &amp; developing, walking, cycling, reading.

Posted 02 September 2006 - 01:34 PM

I personally don't like dynamic includes - I try and reduce needed user input as much as possible. However, bias aside, the main problem with this snippet is that you need to add a new case & include() for each page you want to add. I recently fixed someone else's dynamic includes tutorial which prevents the need to update the php what-so-ever, and removes the risk of malicious usage/etc.

#5 Copernicus

Copernicus

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 05 September 2006 - 01:14 PM

I find it fine using individual pages....like instead of member.php?do=register, just register.php.

#6 Rory

Rory

    Jedi In Training

  • Members
  • PipPip
  • 378 posts
  • Gender:Male
  • Location:Hastings, Hawkes bay, New Zealand
  • Interests:Php, Html, Css, Javascript, ASP.NET, Photoshop, soccer, rigby, cricket, viticulture, Ruby#, C#, AJAX.

Posted 16 September 2006 - 09:18 PM

Cool tut thanks. :D

#7 Arutha

Arutha

    Young Padawan

  • Members
  • Pip
  • 144 posts
  • Gender:Male
  • Location:Southampton, England

Posted 19 February 2007 - 05:05 PM

I find it fine using individual pages....like instead of member.php?do=register, just register.php.


its all about your personal coding preferences ;). I prefer to keep it in seperate files so i don't need to include every file to get all my functions.

Arutha

#8 fosron

fosron

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 20 February 2007 - 07:35 AM

you can use
$page = $_SERVER['QUERY_STRING'];
instead of
$page = $_GET['id'];
, and the links will be
<a href="index.php?oneofthepagesintheswitch">Link</a>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users