0

I am using this code to make a php file become a javascript file

<?php
session_start();
header("Content-Type: text/javascript");
?>

Within the file, I need to get the document's url in both javascript and php.

Javascript returns the URL of the page, but PHP returns the URL of the script.

How can I force PHP to return the URL of the page?

My PHP echo $_SERVER["PHP_SELF"];
My JS    var url = document.URL

user2751288
  • 188
  • 1
  • 17
  • 2
    `$_SERVER["HTTP_REFERER"]` might do the job - although it's not 100% reliable - but then, there is often no point in having a dynamic JS file in the first place. All it does is put unnecessary strain on the server. Are you sure the dynamic parts can't be done in the main HTML file, while serving the main JavaScript (the part that is never going to change) as a static file? – Pekka Sep 20 '13 at 16:30
  • im very sure @Pekka웃 this is a javascript file intended to be on external pages – user2751288 Sep 20 '13 at 16:31
  • http://stackoverflow.com/questions/6768793/php-get-the-full-url may help –  Sep 20 '13 at 16:32

0 Answers0