The Basics
First, I need to teach you the correct URL syntax. You first have your URL, then your file name. Then the file name and the variable are separated by a ?, and then the variables come after. If you have more than one variable, you put a & (and) in between them
supahkewlwow.com/index.php?act=login&username=maverfax
A thing you really need to learn for this is the $_GET. $_GET gets variables inputted in the URL, and stores them in an array. From the example URL above, you could get the act and username by doing this:
<?php $act = $_GET['act']; $username = $_GET['username']; ?>
The Example
Okay, first things first. Since PHP is extremely picky, we first have to check if the $_GET['page'] variable is set. If we didn't, we would get tons of annoying notices.
<?php
#necessary to not get flamed with notices
if( isset($_GET['page']) ) {
}Then, we can add a default value using the else.
<?php
#necessary to not get flamed with notices
if( isset($_GET['page']) ) {
}
#If the page isn't put in the URL, go to index (THIS IS THE DEFAULT VALUE)
else $page = 'index';
?>Now, let's store the $_GET variable as $page:
<?php
#necessary to not get flamed with notices
if( isset($_GET['page']) ) {
#Store the page variable
$page = $_GET['page'];
}
#If the page isn't put in the URL, go to index (THIS IS THE DEFAULT VALUE)
else $page = 'index';
?>The problem with this is that it can easily be hacked into. So let's put a little security. Basically, this checks if the file exists, and if makes sure that the page name isn't too long (a long $_GET['page'] usually means someone's trying to hack you
<?php
#necessary to not get flamed with notices
if( isset($_GET['page']) ) {
#Store the page variable
$page = $_GET['page'];
#Security: checks for if page exists, and then makes sure we aren't trying to be hacked (with a page name greater than 8)
if( !file_exists("pages/{$page}.php") || strlen($page) > 8 ) {
$page = 'index';
}
}
#If the page isn't put in the URL, go to index (THIS IS THE DEFAULT VALUE)
else $page = 'index';
?>And then, you just include the page you want your script to load
<?php
#necessary to not get flamed with notices
if( isset($_GET['page']) ) {
#Store the page variable
$page = $_GET['page'];
#Security: checks for if page exists, and then makes sure we aren't trying to be hacked (with a page name greater than 8)
if( !file_exists("pages/{$page}.php") || strlen($page) > 8 ) {
$page = 'index';
}
}
#If the page isn't put in the URL, go to index (THIS IS THE DEFAULT VALUE)
else $page = 'index';
#Get the page :)
include( "pages/{$page}.php" );
?>And that's how it works.
(p.s. None of this was, like usual, tested. If you get errors post it here and I'll fix it)

Help
















