Accessing a page via POST from within a PHP script
Archive - Originally posted on "The Horse's Mouth" - 2005-09-26 00:03:14 - Graham Ellis
In PHP, you can use a file function to read the whole contents of a file into an array, and you've got a whole variety of other functions to open and read files in other ways too. If you want to read from a web page (a URL) via the GET method, that's easy too - simply put the URL in instead of the file name and PHP will work it out for you.
But what if you want to access a page from your server via the POST method? That's a little more complex, but it can be done; I had cause yesterday, and I wrote a sample posting script ... see full source code.
If you're into this sort of thing, you'll notice I've used the more complex HTTP 1.1 protocol to ensure that my script will work even on virtual hosts sharing a single IP address, and that I've checked for the existance of a robots.txt file. To some extent, the script I've written is an automaton or robot, and so this chsck should be made. It runs very nicely and it's quite a useful tool for learning how HTTP 1.1 and POST protocols work.