Today, the use of QUERY STRING is very common on dynamic WebSites. May not look like it, but it's a very simple thing to do.
Sample 1:
The sample 1 is the most used. see:
<?php ini_set("register_globals", "on");
if($page == "") { // Main Page echo "main page!!"; } elseif($page == "about") { // About page echo "about page!!"; } elseif($page == "contact") { // Contact page echo "contact page!!"; } else { // Page not found echo "Oops.. Page not found (404)"; } ?> |
name it test1.php and try the following URL"s:
test1.php
test1.php?page=about
test1.php?page=contact
test1.php?page=1234
very simple, right? We"ve defined the variable $page by the URL. This is just an example,
you can always change the actions (in this case, echo()).
Sample 2:
this sample may be better, just because we use a predefined variable, called
$QUERY_STRING (everything after page.php?).
<?php
ini_set("register_globals", "on");
if($QUERY_STRING == "") {
// Main Page
echo "main page!!";
} elseif($QUERY_STRING == "about") {
// About page
echo "about page!!";
} elseif($QUERY_STRING == "contact") {
// Contact page
echo "contact page!!";
} else {
// Page not found
echo "Oops.. Page not found (404)";
}
?>
name it test2.php and try the following URL"S:
test2.php
test2.php?about
test2.php?contact
test2.php?1234
almost the same thing, but you don't have to define the variable page!
You can use whatever sample you want. Just enjoy it!