iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 13, 2008
I want to create a site just like ____, is that a violation of...
About
 
May 12, 2008
Film Makers, Bands and Comedians Welcome on MySpace
About
 
May 12, 2008
Software Engineering for Ajax
WebReference.com
 
May 12, 2008
What is the Head Tag For?
About
 
May 11, 2008
Improving accessibility for motor impaired users
WebDevTips UK
 
May 11, 2008
10 ways to orientate users on your site
WebDevTips UK
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /PHP

Using Query String 

  Views:    21431
  Votes:    15
by John Doe 11/26/03 Rating: 

Synopsis:

have you ever asked your self how to do page.php?section=x ? That's what this article will teach you!
Pages: 
The Article

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!

Pages: 

Similar/related articles:


 
  Sponsors