href

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
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

href

Post 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?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: href

Post 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'];
User avatar
TildeHash
Forum Commoner
Posts: 43
Joined: Fri Jul 16, 2010 7:17 am
Location: Apple Valley, California

Re: href

Post 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"];
?>
Live24x7
Forum Contributor
Posts: 194
Joined: Sat Nov 19, 2011 9:32 am

Re: href

Post by Live24x7 »

This should help:
http://knowpapa.com/url/
Post Reply