467,104 Members | 1,041 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,104 developers. It's quick & easy.

PHP_SELF (quick question..)

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
  • viewed: 1549
Share:
5 Replies
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
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
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
Thanks a lot,

This is excactly what i meant.

Greetings
Jul 17 '05 #5
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.

Similar topics

1 post views Thread by jack | last post: by
10 posts views Thread by Snake | last post: by
30 posts views Thread by Christopher Benson-Manica | last post: by
5 posts views Thread by tariq | last post: by
1 post views Thread by Mike | last post: by
6 posts views Thread by z_learning_tester | last post: by
3 posts views Thread by craig | last post: by
2 posts views Thread by Rudy | last post: by
3 posts views Thread by Brian | last post: by
1 post views Thread by JustTrev | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.