I am creating a wordpress plugin and I am having problems with the correct operation of the cURL call.
Let's say I have a page www.domain.com/wp-admin/admin.php?page=orders
On the orders page, I have a function that looks to see if a button has been pressed, and if necessary, you need to make a cURL call on the same page (www.domain.com/wp-admin/admin.php?page = orders & dosomething = true) to run another function. The reason I'm doing this is because I can use this cURL call async.
I am not getting any errors, but I am not getting a response either. If I change my url to google.com or example.com, I will get a response. Perhaps there is an authentication problem or something like that?
My code looks something like this. I use get, echos and do not run async just for the convenience of testing.
if(isset($_POST['somebutton']))
{
curlRequest("http://www.domain.com/wp-admin/admin.php?page=orders&dosomething=true");
}
if($_GET['dosomething'] == "true")
{
echo("do something");
exit;
}
function curlRequest($url) {
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
return($response);
}
source
share