Built-in HTTP request php functions.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Built-in HTTP request php functions.

Post by JellyFish »

Are there built-in php functions that allow me to make post and get HTTP requests? All the functions I've found are extensions why wouldn't php have some of these basic functions built-in?

Are my only options extensions?
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Built-in HTTP request php functions.

Post by Apollo »

With file_get_contents("http://some.random.url/whatever?param=bla") you can get the contents of a remote page, which invokes a normal GET request.

Similarly, file will get the data as an array, and readfile will output the downloaded content directly to your script's own output.

Unfortunately, there is not an easy alternative to do POST requests. You'll have to mess around with fsockopen, or use or something like cURL (the latter is actually quite nice to work with, and also takes care of secure https connections).
Post Reply