farkewie Posted December 13, 2007 Share Posted December 13, 2007 Hi i need to restrict access to a page so only people connected to my router can access them, here is my code but it just always says not ok. PS: the "echo" is just for testing purpose <?php echo $_SERVER['REMOTE_ADDR']; if (($_SERVER['REMOTE_ADDR']) == '192.168.1.\255'){ echo "ok"; } else { echo "not ok"; } ?> also i include 2 php files in my main page how do i stop people accessing them directly? Link to comment https://forums.phpfreaks.com/topic/81515-limit-access-to-page-to-only-local-ip-1921681xx/ Share on other sites More sharing options...
phpQuestioner Posted December 13, 2007 Share Posted December 13, 2007 You can accurately rely on the ip address; because it can be forged - I suggest a user login. Link to comment https://forums.phpfreaks.com/topic/81515-limit-access-to-page-to-only-local-ip-1921681xx/#findComment-413846 Share on other sites More sharing options...
lur Posted December 13, 2007 Share Posted December 13, 2007 if (substr($_SERVER['REMOTE_ADDR'], 0, 10) !== '192.168.1.') exit(); if (!preg_match('/^192\.168\.1\./', $_SERVER['REMOTE_ADDR'])) exit(); if (0 !== strpos($_SERVER['REMOTE_ADDR'], '192.168.1.')) exit(); Link to comment https://forums.phpfreaks.com/topic/81515-limit-access-to-page-to-only-local-ip-1921681xx/#findComment-413849 Share on other sites More sharing options...
farkewie Posted December 13, 2007 Author Share Posted December 13, 2007 Its not a massive security issue, i just dont want to login from home when its set as my homepage, and at the same time i dont want to have too easy access from outside, i dont have a registered domain or anything at home so noone should "stumble" apon it. Link to comment https://forums.phpfreaks.com/topic/81515-limit-access-to-page-to-only-local-ip-1921681xx/#findComment-413851 Share on other sites More sharing options...
revraz Posted December 13, 2007 Share Posted December 13, 2007 If you are behind a router and use NAT (which you do), they can't even get to that address if they tried. Link to comment https://forums.phpfreaks.com/topic/81515-limit-access-to-page-to-only-local-ip-1921681xx/#findComment-413855 Share on other sites More sharing options...
farkewie Posted December 13, 2007 Author Share Posted December 13, 2007 they can because i have forwarded port 80 so i can access it from work and stuff. the above code works.. i think ill have to wait until i get to work to check.. thank you. Link to comment https://forums.phpfreaks.com/topic/81515-limit-access-to-page-to-only-local-ip-1921681xx/#findComment-413867 Share on other sites More sharing options...
PFMaBiSmAd Posted December 13, 2007 Share Posted December 13, 2007 @phpQuestioner The 'REMOTE_ADDR' comes from the TCP/IP packet and cannot be faked. It is the address that the web server will send the response back to. You can easily get a different IP address or go through a web proxy to hide your real IP address, but the IP address in the TCP/IP packet is a true address at the time the pack was created. Link to comment https://forums.phpfreaks.com/topic/81515-limit-access-to-page-to-only-local-ip-1921681xx/#findComment-413875 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.