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 Link to comment https://forums.phpfreaks.com/topic/185727-function-to-kick-users-on-the-page/ 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. Link to comment https://forums.phpfreaks.com/topic/185727-function-to-kick-users-on-the-page/#findComment-980673 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; } ?> Link to comment https://forums.phpfreaks.com/topic/185727-function-to-kick-users-on-the-page/#findComment-980679 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']; Link to comment https://forums.phpfreaks.com/topic/185727-function-to-kick-users-on-the-page/#findComment-980680 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 Link to comment https://forums.phpfreaks.com/topic/185727-function-to-kick-users-on-the-page/#findComment-980686 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! Link to comment https://forums.phpfreaks.com/topic/185727-function-to-kick-users-on-the-page/#findComment-980708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.