$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);


使用上面的代码,当我回显响应时没有问题。
但是当我用以下方式更改回显部分时:

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' )
    );


我网站的大多数状态代码为400或0
我在这里做错了什么。

最佳答案

我发现了问题

我忘记了修剪URL。

$url = trim($fivesdraft->url);


现在工作正常

10-07 13:58