-1

I have a pages on my site which use other PHP files for the content.

Here is an example:

file1.php:

<!-- header and other stuff goes here -->

<?php include 'file2.php; ?>

<!-- footer and other stuff goes here -->

file2.php:

<?php echo $_SERVER['SCRIPT_FILENAME']; ?>
<p>Content goes here.</p>

My problem is that the SCRIPT_FILENAME variable is echoing out as file1.php because it is included in File 1. How do I stop that from happening and get the SCRIPT_FILENAME of the included file (file2.php).

hungerstar
  • 21,206
  • 6
  • 50
  • 59
Connor Wyatt
  • 166
  • 11
  • Because it isn't in the server environment. But you can use the `__FILE__` & `__DIR__` constants as you like. – Wrikken Sep 30 '14 at 14:24

2 Answers2

3

If I'm understanding this correctly, I think you want this in your file2:

echo __FILE__;
andyroo
  • 384
  • 2
  • 13
0

Try echo __FILE__; to echo the full path of the included file.

check the manual here http://php.net/manual/en/language.constants.predefined.php

DerVO
  • 3,679
  • 1
  • 23
  • 27