Page 1 of 1

href

Posted: Sat Aug 11, 2012 9:50 pm
by Vegan
in javascript its known to me how to find the page's URL so I can potentially use it for a range of purposes

if (top!= self) top.location.href = self.location.href; // step out of a frame

so is PHP able to find self.location.href or should I stick to JavaScript?

Re: href

Posted: Tue Aug 14, 2012 1:51 am
by pbs
In PHP you have to use combination of $_SERVER variables.

You can get current URL by using following code

Code: Select all

$href = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

Re: href

Posted: Fri Aug 17, 2012 10:47 pm
by TildeHash
Vegan wrote:in javascript its known to me how to find the page's URL so I can potentially use it for a range of purposes

if (top!= self) top.location.href = self.location.href; // step out of a frame

so is PHP able to find self.location.href or should I stick to JavaScript?
If it's a PHP file that is responsible for the JavaScript output and you're using the JavaScript on the page via the <script> tag, than the following code will give you the full page URL:

Code: Select all

<?php
echo $_SERVER["HTTP_REFERER"];
?>

Re: href

Posted: Sat Aug 18, 2012 1:19 am
by Live24x7
This should help:
http://knowpapa.com/url/