joecooper Posted January 13, 2008 Share Posted January 13, 2008 i have a number of php files that are includes via index.php. and i dont want them to be run directly. how can i do this? Quote Link to comment Share on other sites More sharing options...
tinker Posted January 13, 2008 Share Posted January 13, 2008 someone else might have a better suggestion, but all my includes just contain functions which need calling (except a few with vars in). You could set a global variable in index.php, then each include has an initial section than checks for this variable being set, if not do a redirect with header() Quote Link to comment Share on other sites More sharing options...
joecooper Posted January 13, 2008 Author Share Posted January 13, 2008 eg like this?: index.php: $loaded="yes"; register.php: if($loaded=="yes"){ site stuff }else{ die("Cannot be directly accessed"); } Quote Link to comment Share on other sites More sharing options...
marklarah Posted January 13, 2008 Share Posted January 13, 2008 Or use a session Quote Link to comment Share on other sites More sharing options...
marklarah Posted January 13, 2008 Share Posted January 13, 2008 Ye, because otherwise other people could access it your way, and again. just make sure you kill the variable. Quote Link to comment Share on other sites More sharing options...
tinker Posted January 13, 2008 Share Posted January 13, 2008 not sure how marklarah means. It looks good to me, I personally use: if(strcmp($loaded, "yes")==0) And i'd also do a redirect even if it's to your 404, but why not to the index and bemuse em, let em think they got the upper... Quote Link to comment Share on other sites More sharing options...
trq Posted January 13, 2008 Share Posted January 13, 2008 <?php if (basename($_SERVER['PHP_SELF']) == __FILE__) { die("Cannot access file directly"); } ?> Quote Link to comment Share on other sites More sharing options...
joecooper Posted January 13, 2008 Author Share Posted January 13, 2008 well i have a index page, and sections eg: index.php?section=register where that will include the register.php when called. but dont want register.php called directly. only when included via index.php Quote Link to comment Share on other sites More sharing options...
phpSensei Posted January 13, 2008 Share Posted January 13, 2008 Session would be the easiest way. Quote Link to comment Share on other sites More sharing options...
trq Posted January 13, 2008 Share Posted January 13, 2008 Session would be the easiest way. Yeah, mine is so difficult to implement. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted January 13, 2008 Share Posted January 13, 2008 Session would be the easiest way. Yeah, mine is so difficult to implement. Oh, i didn't see yours lol. Thorpe's way is the best way. sheesh... edit: Thorpe's way, or no way/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.