-1

我通过php制作了一个自定义登录页面。使用CURL我爬网并登录,但我被重定向到空白页面而不是主页。我验证了数据库中的日志表,该表显示已登录。但我经常看到一个空白页。请告诉我哪里出错了。这是我第一次尝试 CURL

4

1 回答 1

1

Make sure that you are handling cURL errors appropriately, i.e. output them...

<?php
    // Create a curl handle to a non-existing location
    $ch = curl_init('http://404.php.net/');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    if(curl_exec($ch) === false)
    {
        echo 'Curl error: ' . curl_error($ch);
    }
    else
    {
        echo 'Operation completed without any errors';
    }

    // Close handle
    curl_close($ch);
?>

Also, read the PHP manual has to say on error handling. A blank page is almost always the result of a script error. With some extra work, you can actually find out what and where the problem is, and then you can fix it.

Typically, in a production environment you would log errors to a log file, but it's okay to echo them to the page for dev purposes. The error log is a massively useful tool as you can even log stuff there that isn't necessarily an error.

于 2012-12-19T10:26:39.730 回答