EchoFool Posted December 19, 2009 Share Posted December 19, 2009 Hey, I can't remember the name of the function to get the name of the script the user is viewing directly? For example: Say users should view include.php directly... they have to view index.php which has it included, i need to some how on include.php add a line to check if the user is viewing it directly, and if so - header them back to index.php. I used to know it but i forgot the function! Hope you can help me here! Thanks Quote Link to comment Share on other sites More sharing options...
George Botley Posted December 20, 2009 Share Posted December 20, 2009 You can achieve this like this: <? //Set Variables $file = $_SERVER['SCRIPT_NAME']; //Check for location to file path. if($file=="/en/1.php") { header('Location: index.php'); } //replace /en/1.php with location to file from your root directory else {} ?> Let me know if that works, if not you will need to use another SERVER tag. Quote Link to comment Share on other sites More sharing options...
EchoFool Posted December 20, 2009 Author Share Posted December 20, 2009 This doesn't work sorry - if i have this in an include named include.php When viewing index.php $file still equals /include.php I still get "no no!" index.php <?php include("include.php"); Echo 'hello'; ?> include.php <?php $file = $_SERVER['SCRIPT_NAME']; if($file == "/include.php") { Echo 'no no!'; die; } ?> Quote Link to comment Share on other sites More sharing options...
david91 Posted December 20, 2009 Share Posted December 20, 2009 Hey, try: $file = $_SERVER['PHP_SELF']; instead of: $file = $_SERVER['SCRIPT_NAME']; Quote Link to comment Share on other sites More sharing options...
teamatomic Posted December 20, 2009 Share Posted December 20, 2009 On your page that includes the file, place above the include(); $view_perm = 'yes'; At the top of the page you dont want viewed unincluded if ($view_perm != 'yes' ) {header('Location: index.php');} HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
EchoFool Posted December 20, 2009 Author Share Posted December 20, 2009 On your page that includes the file, place above the include(); $view_perm = 'yes'; At the top of the page you dont want viewed unincluded if ($view_perm != 'yes' ) {header('Location: index.php');} HTH Teamatomic Works a charm! Thanks! 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.