I have a whole slew of pages, for example ourspacer.com/graphics. In every page on ourspacer.com, I have the same include that shows the link trades and purchased links on the right. In the links on the right, I had a facebook "Like" button. The problem with that Like button is that when you click on it, it puts the URL of the include on facebook, not the URL of the page you are visiting. Is there a way of using PHP to get the URL of the page being viewed from an include on that page? The original function that I was using to determine the URL of the site, which actually gave me the URL of the include, is the following: <?php function PageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } ?> PHP:
Thats weird REQUEST_URI doesn't usually do that. You can try $_SERVER['SCRIPT_NAME'] and $_SERVER['PHP_SELF']
I just tested the code I posted above, and apparently it matters whether you use a relative or absolute URL: http://addressmunger.com/test/
I would of thought it would just be easier to use Javascript to get this done, might save you alot of time and effort! Kind regards, Glen Hughes
That's what I ended up doing. I don't know why the thought didn't even cross my mind. Must be a "slow" day ;-)
Im not too sure what you exactly are looking for but if your looking to retrieve the url of the included file you can look into get_included_files() (which returns an array) and can use it along with the pathinfo() function.