VPmase
New Member
- Messages
- 914
- Reaction score
- 1
- Points
- 0
In this tutorial I'm going to show you how you can have people only go through one page for your entire website.
Functions use:
1) if/then/else
2) switch
3) Global Vars
4) isset
5) in_array
6) include
7) die
I'll show the code then explain it.
That section of code sets the $page variable, which will is very important, to the URI if it is set. (URI is the part of the URL after the ?, in this case it would be "?p=*page*")
Thats a good start, but it is not very secure... Lets make it safer, shall we?
The end of that code is what loads the actual page or if the page doesn't exist it stops the page and displays the error message associated with the problem.
Demo: http://saumpro.com/scripts/other/uritut/main.php
Functions use:
1) if/then/else
2) switch
3) Global Vars
4) isset
5) in_array
6) include
7) die
I'll show the code then explain it.
PHP:
$page = "home";
if(isset($_GET['p'])){
$page = $_GET['p'];
}
?>
Thats a good start, but it is not very secure... Lets make it safer, shall we?
PHP:
$allowedpages[0] = "home"; //You can change this to your page names
$allowedpages[1] = "other"; //You can change this to your page names
$allowedpages[2] = "other2"; //You can change this to your page names
$page = "home";
if(isset($_GET['p']) && in_array($_GET['p'], $allowedpages)){
$page = $_GET['p'];
}
include($page . ".html") or die("Could not find page!"); // You can change the .html to your pages' extentions
The end of that code is what loads the actual page or if the page doesn't exist it stops the page and displays the error message associated with the problem.
Demo: http://saumpro.com/scripts/other/uritut/main.php