I am trying to make a sort of license checking script, but as not all hosts allow curl_exec, I would like to know, if there is any alternative way of making a call-back?
This is how I do it with curl:
curl_setopt($ch, CURLOPT_URL, $url."/my_script.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $info);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
You can simply use
file_get_contents()with URLs:This may be disabled, though, with just a simple INI option
allow_url_fopen.Alternatively, you may use
fsockopen(), which should be available on most systems.With
fsockopen()you can open a socket to a HTTP server, then communicate using standardfwrite()andfread(). The downside is that you must write HTTP request headers by yourself, and you must also parse HTTP response headers too. If you look atfsockopen()on PHP’s manual, you can see plenty of examples: https://www.php.net/fsockopenMy suggestion is to use cURL as primary option, file_get_contents() as secondary (if
ini_get('allow_url_fopen')returns a positive result) and implement solutions likefsockopen()as fallback.