Jump to content


Photo

how to get the current URL of the current page?


  • Please log in to reply
5 replies to this topic

#1 bilis_money

bilis_money
  • Members
  • PipPipPip
  • Advanced Member
  • 621 posts

Posted 05 August 2006 - 12:42 PM

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.



#2 xec

xec
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 05 August 2006 - 12:48 PM

hii ,
          just try

echo $_SERVER['SCRIPT_NAME'];

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

#3 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,430 posts
  • LocationBelgium

Posted 05 August 2006 - 12:53 PM

This depends if you wish to use it into an include I'd rather use

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


#4 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 05 August 2006 - 01:03 PM

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


RTFM is an almost extinct art form, it should be subsidized.

#5 bilis_money

bilis_money
  • Members
  • PipPipPip
  • Advanced Member
  • 621 posts

Posted 05 August 2006 - 01:08 PM

thanks guys, it helped me so much!

THANKS! many thanks!

GOD BLESS you all!

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 05 August 2006 - 01:49 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users