I have a PHP script that runs from our server's non-publicly-accessible directory as a cron task. The script sends cURL POSTs to a publicly-accessible URL.
I set up the receiving URL with a .htaccess file that denies access from any IP address other than the ones I allowed. I ran a PHP script that emailed me the output of a file_get_contents("http://www.whatismyipaddress.com");
to get my server's origin IP address (it's a dedicated server so I don't expect it to change). That's the IP I allowed in the .htaccess file.
But when I ran the script through an SSH prompt, all of the POSTs returned 403 Forbidden errors. When I commented out the .htaccess protections, the POSTs succeeded.
Then I looked at my log files and it turned out the POSTs were coming from a different IP than what was reported by my file_get_contents()
. It was easy enough to add that IP to the .htaccess file, which fixed the problem.
But I'm confused as to why there are two different origin IP addresses. Can anyone shed some light on the subject?