By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,747 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,747 IT Pros & Developers. It's quick & easy.

PHP_SELF (quick question..)

P: n/a
Hi there,

I know the code $PHP_SELF to find out
the name of a file itself. Only if you
include a file with $PHP_SELF in it, it takes
the name of the parent-file.

How do i get the name of the actual file...

Hope this is clear enough.

Greetings
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
knoak wrote:
Hi there,

I know the code $PHP_SELF to find out
the name of a file itself. Only if you
include a file with $PHP_SELF in it, it takes
the name of the parent-file.

How do i get the name of the actual file...


echo __FILE__;

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
Jul 17 '05 #2

P: n/a
Justin Koivisto wrote:
knoak wrote:
Hi there,

I know the code $PHP_SELF to find out
the name of a file itself. Only if you
include a file with $PHP_SELF in it, it takes
the name of the parent-file.

How do i get the name of the actual file...

echo __FILE__;


of course, you could also check:

print_r($_SERVER);

for any relavent entries.

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
Jul 17 '05 #3

P: n/a
Justin Koivisto wrote:
knoak wrote:
Hi there,

I know the code $PHP_SELF to find out
the name of a file itself. Only if you
include a file with $PHP_SELF in it, it takes
the name of the parent-file.

How do i get the name of the actual file...


echo __FILE__;


And if you just want the filename without the directory path etc
echo basename(__FILE__);

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #4

P: n/a
Thanks a lot,

This is excactly what i meant.

Greetings
Jul 17 '05 #5

P: n/a
It's me again:

If i get this right, this would be a waterproof way to protect
pages that are meant to be included from being viewed 'unauthorized':

$page=basename($PHP_SELF);
$file=basename(__FILE__);
if ($page==$file){header('Location: http://domain.com/');}

Is that correct?

Thanks again and greetings..
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.