简体   繁体   English

cURL不工作 - PHP

[英]cURL not working - PHP

I want to connect this site ( https://ais.usvisa-info.com/en-ae/niv/users/sign_in ) with cURL in PHP but blank screen is displayed and no error. 我想用PHP中的cURL连接这个站点( https://ais.usvisa-info.com/en-ae/niv/users/sign_in ),但是显示空白屏幕并且没有错误。 where is the problem? 问题出在哪儿?

Thanks 谢谢

CODE: 码:

<?php
function login($url, $data){
    $fp = fopen("cookie.txt", "w");
    fclose($fp);
    $login = curl_init();
    curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
    curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($login, CURLOPT_TIMEOUT, 40000);
    curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($login, CURLOPT_URL, $url);
    curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($login, CURLOPT_POST, TRUE);
    curl_setopt($login, CURLOPT_POSTFIELDS, $data);
    ob_start();
    return curl_exec ($login);
    ob_end_clean();
    curl_close ($login);
    unset($login);
}
?>

<?php
    echo login("https://ais.usvisa-info.com/en-ae/niv/users/sign_in", 'utf8=✓&authenticity_token=TEST&user[email]=test@yss.com&user[password]=12345&recaptcha_challenge_field=TEST&recaptcha_response_field=TEST&commit=Sing In');
?>

You are echoing out the result of login. 你正在回应登录的结果。 login returns curl_exec($login). login返回curl_exec($ login)。 Since you called curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE); 因为你调用了curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE); , it will return the result on success and FALSE on failure. ,它会在成功时返回结果,在失败时返回FALSE The result is probably an empty string if you do not have an error (take a look at the server logs to be sure). 如果没有错误,结果可能是一个空字符串(请查看服务器日志以确定)。

Read more about the return value here . 在此处阅读有关返回值的更多信息。

By the way, return finishes the function and any further lines after that are completely irrelevant. 顺便说一下, return完成function ,之后的任何其他行完全无关紧要。 Please, store the result of curl_exec into a local variable and return that at the end of the function . 请将curl_exec的结果存储到局部变量中,并在function末尾返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM