RE: [PHP] comparing $php_self with real file name

From: Date: Tue, 15 Apr 2003 11:52:12 +0000
Subject: RE: [PHP] comparing $php_self with real file name
Groups: php.general 
Request: Send a blank email to php-general+get-143916@lists.php.net to get a copy of this message
> -----Original Message----- > From: skate [mailto:root@fatcuban.com] > Sent: 15 April 2003 11:13 > > okay, i've checked thru the manual and can't find what i'm > looking for. i'm > probably not looking hard enough or summit tho, so please excuse... > > if have this... > > <?php > if( basename($_SERVER['PHP_SELF']) == "style.php" ) > { > Header( "Location: ../index.php" ); > } > ?> > > at the top of my style sheet include to stop people accessing > it directly. > but i'd like to this a little more dynamically so i can > include it in every > include file. i want to compare the php_self with the real > file name of that > file... > > but i can't find how to get the real file name? Well the answer to your question is __FILE__ (or basename(__FILE__)), but, IMO, this isn't really the best technical solution to your problem. If possible, it's much better to place all your include files outside of the Web document tree so that they are effectively invisible to your Web server (obviously, this isn't possible if your server provider doesn't give you any storage space outside of the Web tree -- in which case you should lobby them to do so!). Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#143916) next »