2

If, within a php generated page (findmyfilename.php), I embed a JavaScript file (php_js.php) that uses php to generate its content, is there any way within php_js.php that I can find with php the name of the parent i.e. findmyfilename.php?

I have tried

$parentfile = $_SERVER['PHP_SELF']; 
$parentfile = basename(__FILE__);
$parentfile = $_SERVER["SCRIPT_NAME"];
$parentfile = $_SERVER["REQUEST_URI"];
$parentfile = $_SERVER["SCRIPT_FILENAME"];

but these all return php_js.php.

I want to be able to generate the content of php_js.php depending upon the page that called it.

// findmyfilename.php

<!DOCTYPE html> 
<html>

<head>
<title>Find my filename</title>
</head>

<body>

<script type="text/javascript" src="/scripts/php_js.php">

</body>

</html>
martin
  • 393
  • 1
  • 6
  • 21
  • checkout http://stackoverflow.com/questions/5204830/can-an-included-php-file-know-where-it-was-included-from may help – Dhiraj Wakchaure Sep 28 '15 at 12:44
  • Can't you define $parentfile as an javascript variable in findmyfilename.php and use it in php_js.php? – Chris Sep 28 '15 at 12:47
  • Thanks Chris, yes I could, but then I would have to do all my page dependent script in javascript. Which would mean large(the same) files delivered to all the parent pages. – martin Sep 28 '15 at 13:17

0 Answers0