arrays - Do you know a simple php script to throw 403, after ip check? -


I have a script where payment processors come with payment confirmation. To secure the page, because it could use the order information and other related user-related goods, I had to limit access to IP (/ 24) basis, as it is:

  $ ipAllowed = array ('192.192.192', '172.172.172'); $ IpAllowed = str_replace (".", "\.", Implode ("" ", $ ipAllowed)); if (! Preg_match (" / ^ ($ ipAllowed) \. [0-9] {1,3} $ / ', $ _SERVER [' REMOTE_ADDR '])) {Header (' HTTP / 1.0 403 Forbidden '); Dying (' You are not allowed to access this file. ');}   

* IP is in the form of an example

Before I used:

  if (! In_array (@ $ _ SERVER ['REMOTE_ADDR'], array ('Eps' here)); // works only with full IP   

! There were too many layers in them, now I Use me but something Required that works with / 24 IPS, or even with both!

Do you know something which works better / faster, is reliable and very clean? < P> @ rap2-h as you have said that work with full IP, / 24 or even / 16

  $ ipAllowed = array ('192.168) $ .1.153 '' 172.172.172 '); $ Permission = Valid; Foreign Exchange ($ IPA $ specified as IP): If (SRPO ($ _ server [' REMOTE_ADDR '], $ IP) === 0 ) $ Allow = true; Endforeach; If (! $ Permission) {header ('http / 1.0 403 prohibited'); Die ('you do not have permission to access this file.'); }    

You can try something like this:

  $ IpAllowed = array ('192.192.192', '172.172.172'); $ Permission = valid; Foreign exchange ($ IPA $ specified as IP) {If (SRPO ($ _ server ['REMENT_ADDR'], IP) == incorrect) {$ permission = true; }} If (! $ Permission) {header ('http / 1.0 403 prohibited'); Die ('you do not have permission to access this file.'); }   

You can only slice the IP into your $ ipAllowed array. It is not very elegant but it should work ...

Comments