Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

included file being self-aware???

Status
Not open for further replies.

shadedecho

Programmer
Oct 4, 2002
336
US
ok, simple enough (or at least it sounds that way) question:


blah.php:
Code:
<?php

echo &quot;blah<br>\n&quot;;

include(&quot;blah.inc&quot;);

?>


blah.inc:
Code:
<?php

echo $PHP_SELF;

?>

this produces:

blah
blah.php

I want to know how the include file can be &quot;self-aware&quot; such that it knows its own filename, like &quot;blah.inc&quot; or whatever... is there a way to do this?

the output would then be:

blah
blah.inc

Thanks!
 
I thought it was $PHP_SELF (With the underscore)
That's the way I've always seen it used.

And also, everytime I tried using a script with a variable PHP_SELF (or whichever way is correct), it always tells me the PHP_SELF variable is undefined and the whole script won't work.

Any idea what causes this?
 
thanks, that's exactly what I needed!

btw, in versions of PHP prior to 4.0.6, __FILE__ apparently does not give the absolute path, just the filename (making there be no need for basename() in this case).
 
xWastedMindx:

depending on what version of PHP you are running, you may need to refer to that variable as

$HTTP_SERVER_VARS['PHP_SELF']
 
I'm using version 4.3.1

I'll check into that suggestion later tonight when I get the chance. Thanks!

-Kenny
 
xWastedMindx:

It really all depends on the setting of register_globals in php.ini.

If it's set to &quot;off&quot;, then you must, as shadedech has said, reference the variable as $HTTP_SERVER_VARS['PHP_SELF'] or (for newer versions fo PHP) $_SERVER['PHP_SELF'].

Setting it to &quot;on&quot; should enable you to reference it as $PHP_SELF. But I and the online manual recommend ( register_globals set to &quot;off&quot;.

In older versions of PHP, the default setting for register_globals was &quot;on&quot;. In newer versions, the default is &quot;off&quot;. If you are looking at older script examples, they will commonly reference $PHP_SELF, expecting it so be available. Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top