How to get Query String in PHP?
April 30, 2008 · Print This Article
Recently I was implementing a very basic paging system in PHP. The system also supported search functionality, where search parameter was passed in query string, URL was looking like this:
contactlist.php?searchText=some_search_text&pageno=2
contactlist.php or
contactlist.php?pageno=3
The requirement was quite easy I need to append page number to current query string. For those who do not know what is a query string, a small explanation. Query string is used to pass variables. Let’s look at this url:
contactlist.php?searchText=some_search_text&pageno=2
contactlist.php is a script name
Everything that comes after “?” is a query string, so in this example it will be searchText=some_search_text&pageno=2. searchText and pageno are variables and some_search_text and 2 are values. Query string has this form variable1=value&variable2=value, where each variable is separated by ampersand character (”&”).
In PHP we can access query string using superglobal variableRecently I was implementing a very basic paging system in PHP. The system also supported search functionality, where search parameter was passed in query string, URL was looking like this:
contactlist.php?searchText=some_search_text&pageno=2
contactlist.php or
contactlist.php?pageno=3
The requirement was quite easy I need to append page number to current query string. For those who do not know what is a query string, a small explanation. Query string is used to pass variables. Let’s look at this url:
contactlist.php?searchText=some_search_text&pageno=2
contactlist.php is a script name
SERVER, which is an array that contains many useful information. To access query string, use below code:
Recently I was implementing a very basic paging system in PHP. The system also supported search functionality, where search parameter was passed in query string, URL was looking like this:
contactlist.php?searchText=some_search_text&pageno=2
contactlist.php or
contactlist.php?pageno=3
The requirement was quite easy I need to append page number to current query string. For those who do not know what is a query string, a small explanation. Query string is used to pass variables. Let’s look at this url:
contactlist.php?searchText=some_search_text&pageno=2
contactlist.php is a script name
Everything that comes after “?” is a query string, so in this example it will be searchText=some_search_text&pageno=2. searchText and pageno are variables and some_search_text and 2 are values. Query string has this form variable1=value&variable2=value, where each variable is separated by ampersand character (“&”).
In PHP we can access query string using superglobal variable $_SERVER, which is an array that contains many useful information. To access query string, use below code:
$_SERVER['QUERY_STRING']
We should be very careful when appending new variables to query string, because as I showed above, some time query string can be empty and sometimes it can already contains some variables, because of this before appending new variable, we should check if we have to append ampersand character (“&”) before or not. This can be done by simple if statement presented below. Below code example also uses $_SERVER["PHP_SELF"], which returns script name
<?php $self = $_SERVER["PHP_SELF"]; if($_SERVER["QUERY_STRING"]) { $finalurl = $self . "?" . $_SERVER["QUERY_STRING"] . "&myvariable=myvalue"; } else { $finalurl = $self . "?" . "myvariable=myvalue"; } ?>
I hope this simple example will help some one.



















Hi need help geting a variable from an remote address example
http://www.remoteaddress.com/id=geniqgn
I need a php code that can store the id inside a variable please help me
edisonlau90@gmail.com
Variables from query string can be retrieved using $_GET array, like in this example:
$myvar = $_GET["id"];
Regards
Krystian Zieja
buy@generic.LEVITRA” rel=”nofollow”>……
Need cheap generic LEVITRA?…
Buy@Cheap.Abana” rel=”nofollow”>..…
Buygeneric pills…
Purchase@Abilify.Online” rel=”nofollow”>……
Buywithout prescription…
Buy@Generic.Abilify.5mg.10mg.15mg.20mg.30mg” rel=”nofollow”>……
Buywithout prescription…
Purchase@Discount.Acai” rel=”nofollow”>..…
Buywithout prescription…
Buy@Acai.Without.Prescription” rel=”nofollow”>……
Buynow…
Buy@Cheap.Coral.Calcium” rel=”nofollow”>.…
Buynow it…
Buy@Cheap.Coral.Calcium” rel=”nofollow”>……
Buygeneric meds…
Cheap@Coral.Calcium.Online” rel=”nofollow”>..…
Buygeneric drugs…
Order@Discount.Abana” rel=”nofollow”>..…
Buygeneric meds…
Cheap@Abana.Online” rel=”nofollow”>..…
Buynow it…
Buy@Cheap.Abilify” rel=”nofollow”>……
Buygeneric pills…
Cheap@Abilify.Without.Prescription” rel=”nofollow”>..…
Buyno prescription…
Order@Accupril.Online” rel=”nofollow”>.…
Buygeneric drugs…
Buy@Discount.Accutane” rel=”nofollow”>.…
Buynow it…
.…
Buygeneric drugs…
Buy@Aciphex.20mg” rel=”nofollow”>.…
Buygeneric meds…
Cheap@Generic.Actonel.35mg” rel=”nofollow”>..…
Buygeneric meds qmo…
Get@Actos.Online” rel=”nofollow”>..…
Buywithout prescription dyo…
Cheap@Coral.Calcium.Online” rel=”nofollow”>……
Buywithout prescription xiu…
Get@Abana.Online” rel=”nofollow”>.…
Buygeneric drugs zfk…
Buy@Cheap.Accupril” rel=”nofollow”>.…
Buygeneric drugs nih…
Cheap@Accupril.Online” rel=”nofollow”>..…
Buygeneric drugs ajd…
Cheap@Accutane.10mg.20mg” rel=”nofollow”>.…
Buyit now ojb…
Order@Aciphex.Online” rel=”nofollow”>.…
Buynow it lmg…
Order@Discount.Aciphex” rel=”nofollow”>……
Buygeneric meds svb…
Cheap@Advair.Without.Prescription” rel=”nofollow”>……
Buyit now sge…
Buy@Cheap.Aggrenox” rel=”nofollow”>..…
Buygeneric meds dxy…
Buy@Cheap.Aldactone” rel=”nofollow”>..…
Buydrugs without prescription hak…
can@you.take.aciphex.and.nexium.at.the.same.time” rel=”nofollow”>..…
Buygeneric pills…
actonel@and.heart.irregularities” rel=”nofollow”>..…
Buyno prescription…
aldactone@kidney.problems” rel=”nofollow”>……
Buygeneric drugs…
actonel@and.dvt” rel=”nofollow”>.…
Buygeneric meds…
levaquin 500mg…
Buy_no prescription…
financial aid for alzheimer’s…
Buy_without prescription…
heart worm medication…
Buy_no prescription…
blood pressure medications…
Buy_now it…
hepatitis b shot…
Buy_it now…
drug trafficking in latin america…
Buy_drugs without prescription…
permanent removal of adult acne scars…
Buy_generic meds…
enhancement drugs…
Buy_no prescription…
drug test company…
Buy_without prescription…
epson salt and lemon juice diet…
Buy_generic pills…
l91 energizer e2 lithium aa cells…
Buy_generic drugs…
how to buy glucose meter…
Buy_generic meds…
skin cancer foundation australia…
Buy_generic drugs…
clinical features of sickle cell disease…
Buy_generic drugs…
depression medcine xr…
Buy_drugs without prescription…
school age adhd self absorbed…
Buy_now it…
meal plan for hypertension…
Buy_generic drugs…
scabies in dogs help…
Buy_generic drugs…
herbals for pregnancy…
Buy_drugs without prescription…
diet secrets for models…
Buy_now it…
best@medicare.plan.d.for.nexium.40.mg” rel=”nofollow”>..…
Buygeneric meds…
infant@prevacid.dose” rel=”nofollow”>.…
Buygeneric drugs…