Getting the value of the address bar

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Getting the value of the address bar

Post by evilmonkey »

Hello. Can someone please tellme how I can get the value of the adress bar? I have a script that does something to the effect of:

Code: Select all

script.php?var1=value1&var2=value2&var3-value3..
for about 6 or 7 values. $_SERVER['PHP_SELF'] returns only script.php, I need the value of the whole bar. How can I find it? Thanks!
User avatar
xjake88x
Forum Commoner
Posts: 50
Joined: Sun Aug 01, 2004 7:05 pm

Post by xjake88x »

Use javascript.. location.href
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Thanks Jake!
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Or in php:

Code: Select all

$_SERVER['QUERY_STRING'];
$_SERVER['REDIRECT_QUERY_STRING'];
Or you can just do a foreach on $_POST.
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Actually, I decided to do this:

Code: Select all

<?php
//after I converted the variables from $_POST
$url = $_SERVER['PHP_SELF']."?var1=$var1&var2=$var2"//...etc
?>
Also, kettle_drum, that would be a foreach on $_GET ;)
burzvingion
Forum Newbie
Posts: 11
Joined: Sun Apr 18, 2004 2:30 pm

Post by burzvingion »

kettle_drum wrote:Or in php:

Code: Select all

$_SERVER['QUERY_STRING'];
$_SERVER['REDIRECT_QUERY_STRING'];
Or you can just do a foreach on $_POST.
$_SERVER indexes vary by system/server. if you want the whole absolute url:

Code: Select all

$url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
// or if you're sure theres going to be GET data:
$url = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
All those $_SERVER vars are available with apache
Post Reply