Smudly Posted July 11, 2010 Share Posted July 11, 2010 Hi, I need to add some security to some pages and even some directories so users are not able to view them. What do I need to do to prevent users from viewing pages? Quote Link to comment https://forums.phpfreaks.com/topic/207450-how-to-prevent-users-from-viewing-certain-pages/ Share on other sites More sharing options...
.josh Posted July 11, 2010 Share Posted July 11, 2010 all users or specific users? If you are wanting to prevent all users from viewing them, store the pages and directories in a directory outside of your publicly accessible directory. If you only want to restrict some users, then it really depends on what your overall system/site looks like, what it's for etc.. but in general, that's where a login/membership system comes into play. Quote Link to comment https://forums.phpfreaks.com/topic/207450-how-to-prevent-users-from-viewing-certain-pages/#findComment-1084598 Share on other sites More sharing options...
dezkit Posted July 12, 2010 Share Posted July 12, 2010 Well if you are not using an admin system you can use this -> using array: $blockIPs = "192.168.1.1,127.0.0.1"; $blockIPs = explode(",",$blockIPs); foreach($blockIPs as $IP){ if($_SERVER['REMOTE_ADDR'] == trim($IP)){ header("location: you-are-banned.html"); } } using database: $result = mysql_query("SELECT * FROM ip_ban_list") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { if($_SERVER['REMOTE_ADDR'] == $row["ip"]){ header("location: you-are-banned.html"); } } oh and btw-CV, I just totally got suprised when I saw a quote of mine in your signature, haha! Quote Link to comment https://forums.phpfreaks.com/topic/207450-how-to-prevent-users-from-viewing-certain-pages/#findComment-1084711 Share on other sites More sharing options...
marcus Posted July 12, 2010 Share Posted July 12, 2010 @dezkit There is no need to loop through an array or a database to use a method like yours. If this person is using an array they simply just need to use in_array or for a database use a more specific SELECT statement $sql = "SELECT * FROM `ip_bans` WHERE `ip`='".$_SERVER['REMOTE_ADDR']."'"; Quote Link to comment https://forums.phpfreaks.com/topic/207450-how-to-prevent-users-from-viewing-certain-pages/#findComment-1084713 Share on other sites More sharing options...
ignace Posted July 12, 2010 Share Posted July 12, 2010 @dezkit There is no need to loop through an array or a database to use a method like yours. If this person is using an array they simply just need to use in_array or for a database use a more specific SELECT statement $sql = "SELECT * FROM `ip_bans` WHERE `ip`='".$_SERVER['REMOTE_ADDR']."'"; Would it not be easier to create a whitelist instead of a blacklist as it's about a few select users? Quote Link to comment https://forums.phpfreaks.com/topic/207450-how-to-prevent-users-from-viewing-certain-pages/#findComment-1084967 Share on other sites More sharing options...
xjermx Posted July 12, 2010 Share Posted July 12, 2010 As someone else may have pointed out, using a login system and $_SESSION variables may do this for you. I can provide some simple code examples if you like. Quote Link to comment https://forums.phpfreaks.com/topic/207450-how-to-prevent-users-from-viewing-certain-pages/#findComment-1085029 Share on other sites More sharing options...
marcus Posted July 12, 2010 Share Posted July 12, 2010 @ignace A whitelist would most likely have more entries than a blacklist. It depends on how you go about achieving the problem. Blacklists with less entries would be quicker to cycle through. Quote Link to comment https://forums.phpfreaks.com/topic/207450-how-to-prevent-users-from-viewing-certain-pages/#findComment-1085031 Share on other sites More sharing options...
ignace Posted July 12, 2010 Share Posted July 12, 2010 @ignace A whitelist would most likely have more entries than a blacklist. It depends on how you go about achieving the problem. Blacklists with less entries would be quicker to cycle through. So if you want to limit access to your website for you (82.16.15.78) and 2 of your friends (86.57.15.63, 87.15.75.98) is more then the rest of the internet (~4 billion, as only your friends are allowed) to cycle through? Quote Link to comment https://forums.phpfreaks.com/topic/207450-how-to-prevent-users-from-viewing-certain-pages/#findComment-1085070 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.