$datetime = date("Y-m-d H:i:s");
$timeout = 10;
$redirect = 10;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $fivesdraft->url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36");
curl_setopt ($ch,CURLOPT_MAXREDIRS, $redirect);
curl_setopt ($ch,CURLOPT_HEADER, true);
curl_setopt ($ch,CURLOPT_ENCODING, " ");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch, CURLOPT_NOBODY, true);
$http_respond = curl_exec($ch);
$http_respond = trim(strip_tags($http_respond));
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$redirectURL = curl_getinfo($ch,CURLINFO_REDIRECT_URL);
echo '$fivesdraft->url';
echo '$http_code';
echo '$redirectURL';
curl_close($ch);
With the above code there is no problem when i echo the response. but when i change the echo part with :
global $wpdb;
$wpdb->update(
'tp_backlinks',
array(
'last_checkd' => $datetime,
'last_status' => $http_code,
'last_redirect' => $redirectURL
),
array( 'ID' => $fivesdraft->ID ),
array(
'%s',
'%d',
'%s'
),
array( '%d' )
);
most of my website's give a status code 400 or 0 What am i doing wrong here.
I found The problem,
I was forgetting to Trim my URL.
$url = trim($fivesdraft->url);
Now it works fine