i'm trying to check my email with curl.
我正试图用卷曲检查我的电子邮件。
I've got a function which connects to gmail:
我有一个连接到gmail的函数:
function check_email($url)
{
// sendRequest
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0);
$curlData = curl_exec($curl);
curl_close($curl);
//returning retrieved message
return $curlData;
}
When I call the function and echo it ($email = check_email($ur); echo $email;
), gmail sends me some html instead of showing the message:
当我调用该函数并回显它($ email = check_email($ ur); echo $ email;)时,gmail会向我发送一些html而不是显示消息:
<HTML>
<HEAD>
<TITLE>Moved Temporarily</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Moved Temporarily</H1>
The document has moved <A HREF="-very large url-">here</A>.
</BODY>
</HTML>
so i want to then extract the "-very large url-"
and curl to that, but when i var_dump($email)
it says it's a bool! why is it returning html if it's a boolean and how can i get to the aforementioned html via php?
所以我想然后提取“-very large url-”并卷曲到那个,但是当我var_dump($ email)它说它是一个bool!为什么它返回html如果它是一个布尔值,我怎么能通过PHP获得前面提到的HTML?
2 个解决方案
#1
1
http://php.net/manual/en/function.curl-exec.php says
http://php.net/manual/en/function.curl-exec.php说
Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure.
成功时返回TRUE,失败时返回FALSE。但是,如果设置了CURLOPT_RETURNTRANSFER选项,它将在成功时返回结果,在失败时返回FALSE。
Looks like you've got CURLOPT_RETURNTRANSFER
set to 0 (false).
看起来你已经将CURLOPT_RETURNTRANSFER设置为0(false)。
http://php.net/manual/en/function.curl-setopt.php
http://php.net/manual/en/function.curl-setopt.php
#2
2
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
Shall be used if you want curl_exec()
to return anything other than boolean.
如果你想让curl_exec()返回除boolean之外的任何东西,那么应该使用。
#1
1
http://php.net/manual/en/function.curl-exec.php says
http://php.net/manual/en/function.curl-exec.php说
Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure.
成功时返回TRUE,失败时返回FALSE。但是,如果设置了CURLOPT_RETURNTRANSFER选项,它将在成功时返回结果,在失败时返回FALSE。
Looks like you've got CURLOPT_RETURNTRANSFER
set to 0 (false).
看起来你已经将CURLOPT_RETURNTRANSFER设置为0(false)。
http://php.net/manual/en/function.curl-setopt.php
http://php.net/manual/en/function.curl-setopt.php
#2
2
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
Shall be used if you want curl_exec()
to return anything other than boolean.
如果你想让curl_exec()返回除boolean之外的任何东西,那么应该使用。