Open URL with PHP

I am trying to open a URL that notifies the third part of the sale. All I have to do is open the url to notify a third party. I usually used an image or iframe pixel to open it, but I cannot let the user see it.

Is there an easy way to do this with php before the page loads?

+7
source share
2 answers

Ben Lee's file_get_contents method only offers to work if allow_url_fopen included in php.ini . Although this option is enabled by default, many (wise) sysadmins disable this flag .

In this case, using curl is the best option .

Since you only ping the remote URL, you do not even need complex options:

 $ch = curl_init("http://www.example.com/"); curl_exec($ch); 

Although you can have small-scale control over the request and response when using curl if necessary in the future.

+24
source

Update: see @Remco Overdijk answer. Its better.


You can simply do:

 file_get_contents('http://www.example.com/'); 

See http://php.net/manual/en/function.file-get-contents.php

+18
source

All Articles