...

View Full Version : get URL using php



nickyfraggle
07-05-2007, 05:43 PM
Hello,

I'm writing a send to a friend script which sends the URL of a webpage to an email address that the user puts into a form.

I'm having trouble getting the URL of the page if it is something like articles.php?category=news

I can handle simple filenames fine like articles.php works no problem.


$dirandfile = basename($_SERVER['PHP_SELF']);
$domain = $_SERVER['SERVER_NAME'];
$url = "http://$domain/$dirandfile";

How can I get my script to handle these url's?

Thank you,

Nicola

ess
07-05-2007, 06:50 PM
Hi Nicola,

try the following


$_SERVER['REQUEST_URI']

the result should be something like

/articles.php?category=news

Cheers,
Ess

phpandmysql
07-05-2007, 07:00 PM
This should do it:



$currentpage = $_SERVER['REQUEST_URI'];
$domain = $_SERVER['SERVER_NAME'];
$domain = str_replace('www.', '', $domain);
$domain = "http://www.$domain";
$fullurl = "$domain$currentpage";


you can echo currentpage, domain and fullurl seperately to see each result. I believe you are looking for the fullurl.

Enjoy.

nickyfraggle
07-07-2007, 10:35 AM
Thank you!!

That's great...

Nicky



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum