Filename and variables

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
Tubby
Forum Commoner
Posts: 28
Joined: Thu Oct 17, 2002 5:55 pm

Filename and variables

Post by Tubby »

Hi,
Is there a way to grab certain parts from an URL and echo them into a form.
i.e. the url is
http://www.domain.tld/dir/main.php?page=24&id=42
and i want it to echo the `main?page=24&id=42` part into a form feild
$PHP_SELF returns /dir/main.php which is no good to me because i also want the variables but not the directory name.

I would hard code it as:
main.php?page=$page_no&id=$id
but the filename isnt always main.php and the variables are not always page and id.

Any help would be appriciated.
:)
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

$_SERVER['QUERY_STRING'] for the query string and I think that $_SERVER['SCRIPT_NAME'] will get the name of the file you are in (but I am not positive, as I have never used it)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Code: Select all

echo '<pre>';
print_r($_SERVER);
echo '</pre>';
will show you all the contents of the $_SERVER array.

Mac
User avatar
Tubby
Forum Commoner
Posts: 28
Joined: Thu Oct 17, 2002 5:55 pm

Thanks for your time

Post by Tubby »

Thanks :)
Post Reply