-2

I have a php script on my site that, when run, changes the 'Dog of the Day' on my home page. I have a cron job set up to run the script once a day, and everything works perfectly.

I've secured my 'scripts' directory with an .htaccess file, because if someone stumbles upon the php script, it'll be run, causing the 'Dog of the Day' to be updated.

ErrorDocument 404 /404.php

order deny,allow
deny from all
allow from 127.0.0.1

I changed the cron job to run every minute, but the .htaccess is blocking it, despite 127.0.0.1 being whitelisted. I changed 127.0.0.1 to my own ip, and I can access it, so it's not a problem with syntax.

I'm a graphics designer by trade, and a front-end coder at a push, so keep it simple please!

Thanks a lot!

1 Answer 1

3

Your script being run from cron is not accessing your own site on the same server via 127.0.0.1, but by its actual IP address.

For instance, you are probably doing something like:

curl http://www.example.com/scripts/update-dog-of-the-day.php

But www.example.com doesn't resolve to localhost, but to your public IP address.

To resolve the issue, whitelist your public IP address instead.

Allow from 203.0.113.17
5
  • Awesome. I'll try it when I get home... so what exactly is 203.0.113.17? When I look it up, it's an IP from China!
    – Starkers
    Mar 12, 2013 at 23:09
  • I really doubt that you found that IP address in China. It is a reserved address for use in documentation and should never be seen on the public Internet. This makes it useful for examples. See RFC 5737. Mar 12, 2013 at 23:13
  • So 203.0.113.17 is just an example?
    – Starkers
    Mar 12, 2013 at 23:29
  • Precisely. Just like www.example.com is an example. (It's defined in RFC 2606.) Mar 12, 2013 at 23:30
  • Right, I was wondering how you knew!
    – Starkers
    Mar 12, 2013 at 23:34

Not the answer you're looking for? Browse other questions tagged .