The one Shane did is secure enough I believe

The one Shane did is secure enough I believe
Hi, names James. I am a web developer.
I'd do this; but you being able to add the content via a different page, but included on the $_GET.
PHP Code:<?php
$_GET['navigation'];
switch ($_GET['navigation']):
case "home":
include "home.php";
break;
case "contact":
include "contact.php";
break;
case "freeporn":
include "freeporn.php";
break;
default:
echo "You did not enter a valid page name into the navigation URL.";
endswitch;
?>
The code I posted should be safe seeing as I originally discovered it on ask.com or one of the other professional PHP wiki sites
I'm presuming your div coding looks something like this currently?
You'd take out the welcome message and put that into the file called main.php which will be shown automatically. You will put the PHP code inside the welcome message comments , where your text previously was.Code:<div id="container"> <div id="banner"></div> <div id="mid"> <div id="left"> <div id="box"> Dummy text </div> <div id="nav"> <!-- Nav links --> Link Link Link Link Link <!-- End Nav --> </div> </div> <div id="right"> <div id="content"> <!-- Welcome message --> Welcome to Site.com , blah blah blah. <!-- End message --> </div> </div> </div> <div id="footer"></div> </div>
You then replace the nav links with the news ones so you should end up with it being:
Quite hard to explainCode:<div id="container"> <div id="banner"></div> <div id="mid"> <div id="left"> <div id="box"> Dummy text </div> <div id="nav"> <!-- Nav links --> <a href="index.php?p=about">About</a> <a href="index.php?p=news">News</a> <a href="index.php?p=staff">Staff</a> <!-- End Nav --> </div> </div> <div id="right"> <div id="content"> <!-- Welcome message --> <?php $page = $_GET['p']; if(!isset($page)) { include("main.php"); } elseif(file_exists("". $page . ".php")) { include("" . $page . ".php"); } else { print("The page <b>" . $page . ".php</b> does not exist."); } ?> <!-- End message --> </div> </div> </div> <div id="footer"></div> </div>![]()
I'll try;
I have a navigation, latest news, updates and a seperate box on the left and a content box on the right. In the content box I place this code and it will show main.php upon load of the site. I then click the relevant tab on the navigation say, about and it brings up about.php in the content box only but still loads the div's on the left?
Yep, nothing will change other than the div the php is in, that div will load the content for youI'll try;
I have a navigation, latest news, updates and a seperate box on the left and a content box on the right. In the content box I place this code and it will show main.php upon load of the site. I then click the relevant tab on the navigation say, about and it brings up about.php in the content box only but still loads the div's on the left?.
That's what I wanted to know
Thanks Legend.
Just another methodPHP Code:<?php
$page = $_GET[ "page" ]; // Change this for whatever you want the word after "?" be. (EG, using "page" you will do "?page=blah").
$args = array( ".", "http", "www", "/", "\\" ); // This stops people from getting files in other directories.
$page = str_replace( $args, "", $page );
if( isset( $page ) && trim( $page ) != "" )
{
include( $page . '.php' );
}
elseif( !isset( $page ) && trim( $page ) == "" )
{
include( "main.php" ); // This is the page that will be shown if you don't specify to load another page.
}
else
{
include( "404.php" ); // This is the page that will be shown if the page specified to load doesn't exist.
}
?>![]()
Last edited by Invent; 27-07-2008 at 05:12 PM.
Switch case things are better than IF statements, as simon taught me in another thread.The code I posted should be safe seeing as I originally discovered it on ask.com or one of the other professional PHP wiki sites
I'm presuming your div coding looks something like this currently?
You'd take out the welcome message and put that into the file called main.php which will be shown automatically. You will put the PHP code inside the welcome message comments , where your text previously was.Code:<div id="container"> <div id="banner"></div> <div id="mid"> <div id="left"> <div id="box"> Dummy text </div> <div id="nav"> <!-- Nav links --> Link Link Link Link Link <!-- End Nav --> </div> </div> <div id="right"> <div id="content"> <!-- Welcome message --> Welcome to Site.com , blah blah blah. <!-- End message --> </div> </div> </div> <div id="footer"></div> </div>
You then replace the nav links with the news ones so you should end up with it being:
Quite hard to explainCode:<div id="container"> <div id="banner"></div> <div id="mid"> <div id="left"> <div id="box"> Dummy text </div> <div id="nav"> <!-- Nav links --> <a href="index.php?p=about">About</a> <a href="index.php?p=news">News</a> <a href="index.php?p=staff">Staff</a> <!-- End Nav --> </div> </div> <div id="right"> <div id="content"> <!-- Welcome message --> <?php $page = $_GET['p']; if(!isset($page)) { include("main.php"); } elseif(file_exists("". $page . ".php")) { include("" . $page . ".php"); } else { print("The page <b>" . $page . ".php</b> does not exist."); } ?> <!-- End message --> </div> </div> </div> <div id="footer"></div> </div>
Only in certain circumstancesSwitch case things are better than IF statements, as simon taught me in another thread.![]()
You're just extraJust another methodPHP Code:<?php
$page = $_GET[ "page" ]; // Change this for whatever you want the word after "?" be. (EG, using "page" you will do "?page=blah").
$args = array( ".", "http", "www", "/", "\\" ); // This stops people from getting files in other directories.
$page = str_replace( $args, "", $page );
if( isset( $page ) && trim( $page ) != "" )
{
include( $page . '.php' );
{
elseif( !isset( $page ) && trim( $page ) == "" )
{
include( "main.php" ); // This is the page that will be shown if you don't specify to load another page.
}
else
{
include( "404.php" ); // This is the page that will be shown if the page specified to load doesn't exist.
}
?>
Nope they're not, it depends on what you're trying to with them. Lets say you have a large site with around 60 pages, it's not like you're going to make a case for each page and keep adding new ones each time when you can simply let the PHP automatically find the page for you. But if you were to do something simple like having a GD library image form with like 3 or 4 options then switches would do the job better.
Want to hide these adverts? Register an account for free!