How do I limit my PHP script to only run when requested by localhost? -


i'm having trouble getting php page run when requested server itself.

this have right now:

if ($_server['server_addr'] == $_server['remote_addr']) {         //process page } else {         $this->redirect('http://' . $_server['http_host'] . '/404'); } 

however, when curl it, doesn't give errors or return @ all. if remove check, spits out html expected.

i tried echoing both of values , got 192.168.1.186, , 192.168.1.225 respectively. realize different (this being run server itself), how can fix it? code this s.o answer

the title of question implies can provide answer doesn't quite match body of question.

my response putting entire script in giant if statement seems somehow insecure , unmaintainable.

you need guard if possible other computers run script, accessing web.

but, if server machine can run script, why not put in place server can access it? instance, 1 directory level above web-accessible directory or in child-directory 700 permissions. or use .htaccess limit access.

that seems both safer , more maintainable.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -