I am fairly beginner level in php and have an API from which I want to read out data. On my localhost it works fine and all outputs are as expected. Same goes for Postman app. It even works when I adress the web API from my localhost instead of my local API. BUT as soon as I try to get a result ON my live website it returns NULL. Note: Its a wordpress site. Localhost is done via Xampp. Online hosting via SiteGround. I had this working in the past but I dont know what happend (maybe I changed code slightly or something else) that is suddenly stopped working. API is a wordpress license manager plugin with preconfigured API. Domain name/IP/ and customer secrets are not original here.
Please any idea is appreciated I have been stuck on this for days!
$url = "https://example.com/wp-json/lmfwc/v2/licenses?consumer_key=ck_xxxx&consumer_secret=cs_yyy";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_FOLLOWLOCATION => True,
CURLOPT_HTTPHEADER =>array (
'Accept: application/json'),
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
));
$response = curl_exec($curl);
print_r($response) ?> <br><br> <?php ;
$json_response =json_encode($response);
print_r($json_response) ?> <br><br> <?php ;
$info_display = curl_getinfo($curl);
print_r ($info_display); ?> <br><br> <?php
$array_response = json_decode($response);
print_r($array_response); ?> <br> <br><?php
$err = curl_error($curl);
var_dump($err); ?> <br> <br><?php
curl_close($curl);
On my localhost this code produces this response which is exactly what I need:
{"success":true,"data":{"id":"1","orderId":null,"productId":"2037","licenseKey":"1232edwfsd2","expiresAt":null,"validFor":"14","source":"2","status":"3","timesActivated":"0","timesActivatedMax":"1","createdAt":"2020-02-06 20:35:56","createdBy":"1","updatedAt":"2020-02-08 12:34:20","updatedBy":"1"}}
"{\"success\":true,\"data\":{\"id\":\"1\",\"orderId\":null,\"productId\":\"2037\",\"licenseKey\":\"1232edwfsd2\",\"expiresAt\":null,\"validFor\":\"14\",\"source\":\"2\",\"status\":\"3\",\"timesActivated\":\"0\",\"timesActivatedMax\":\"1\",\"createdAt\":\"2020-02-06 20:35:56\",\"createdBy\":\"1\",\"updatedAt\":\"2020-02-08 12:34:20\",\"updatedBy\":\"1\"}}"
Array ( [url] => https://example.com/wp-json/lmfwc/v2/licenses?consumer_key=ck_xxx&consumer_secret=cs_yyy [content_type] => application/json; charset=UTF-8 [http_code] => 200 [header_size] => 657 [request_size] => 250 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 2.164129 [namelookup_time] => 0.000694 [connect_time] => 0.256472 [pretransfer_time] => 0.40321 [size_upload] => 0 [size_download] => 205 [speed_download] => 94 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 2.164067 [redirect_time] => 0 [redirect_url] => [primary_ip] => censored by author [certinfo] => Array ( ) [primary_port] => 443 [local_ip] => censored by author [local_port] => censored by author [http_version] => 3 [protocol] => 2 [ssl_verifyresult] => 0 [scheme] => HTTPS [appconnect_time_us] => 403002 [connect_time_us] => 256472 [namelookup_time_us] => 694 [pretransfer_time_us] => 403210 [redirect_time_us] => 0 [starttransfer_time_us] => 2164067 [total_time_us] => 2164129 )
stdClass Object ( [success] => 1 [data] => stdClass Object ( [id] => 1 [orderId] => [productId] => 2037 [licenseKey] => 1232edwfsd2 [expiresAt] => [validFor] => 14 [source] => 2 [status] => 3 [timesActivated] => 0 [timesActivatedMax] => 1 [createdAt] => 2020-02-06 20:35:56 [createdBy] => 1 [updatedAt] => 2020-02-08 12:34:20 [updatedBy] => 1 ) )
string(0) ""
status: 3 times activated: 0 times activated max: 1 last update: 2020-02-08 12:34:20
The same code on my live website crashes. So I need to comment out //print_r($response) ?>
"</meta></head></html>"
Array ( [url] => https://example.com/wp-json/lmfwc/v2/licenses?consumer_key=ck_xxx&consumer_secret=cs_yyy [content_type] => text/html [http_code] => 200 [header_size] => 277 [request_size] => 254 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.01762 [namelookup_time] => 0.000747 [connect_time] => 0.000873 [pretransfer_time] => 0.016955 [size_upload] => 0 [size_download] => 96 [speed_download] => 5647 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0.017479 [redirect_time] => 0 [redirect_url] => [primary_ip] => censored by author [certinfo] => Array ( ) [primary_port] => 443 [local_ip] => censored by author [local_port] => censored by author [http_version] => 3 [protocol] => 2 [ssl_verifyresult] => 0 [scheme] => HTTPS [appconnect_time_us] => 16862 [connect_time_us] => 873 [namelookup_time_us] => 747 [pretransfer_time_us] => 16955 [redirect_time_us] => 0 [starttransfer_time_us] => 17479 [total_time_us] => 17620 )
string(0) ""
status: times activated: times activated max: last update:
Aucun commentaire:
Enregistrer un commentaire