Jump to content

Archived

This topic is now archived and is closed to further replies.

bilis_money

how to get the current URL of the current page?

Recommended Posts

ok,

let say i have a web page namely mypage1.php

now also let say we are currently in mypage1.php,
how could i get its current URL, using PHP?

thanks in advance.

Share this post


Link to post
Share on other sites
hii ,
          just try

echo $_SERVER['SCRIPT_NAME'];

and u will get what you want.... :)

Share this post


Link to post
Share on other sites
This depends if you wish to use it into an include I'd rather use

[code]
echo $_SERVER['SCRIPT_FILENAME'];// returns absolute path c:\path\to\script\filename.php
[/code]

Share this post


Link to post
Share on other sites
And if you want the full http for use in a link (e.g. in an email):
[code]$url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; // gives http://www.domain.name/mypage1.php[/code]

Share this post


Link to post
Share on other sites
If you want to get the url parameters too (eg index.php?var=foo&var2=bar) you can use $_SERVER['QUERY_STRING']

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.