没有回复卷曲

时间:2012-06-27 02:55:57

标签: php curl

我正在尝试使用curl将我的用户名和密码传递到网站www.licindia.in,但我可能会遇到cookie问题,我无法继续我的会话和网站响应302错误,该文档已被暂时移动,现在我对此代码没有回应: -

<?php
    $username="myusername";
    $password="password";
    $url="http://onlinelic.in/LICEPS/Login/webLogin.do";
    //echo "praveenpuglai";
    $postdata = "portlet_5_6{actionForm.userName}=".$username."&portlet_5_6{actionForm.password}=".$password;
    $cookie = "JSESSIONID";
    ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0");
    curl_setopt($ch,CURLOPT_COOKIESESSION,true);
    curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_REFERER, $url);
    //var_dump($ch);
    curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
    curl_setopt ($ch, CURLOPT_POST, 1);
  //  $result = curl_exec ($ch);
    //echo $result;
    /*if($result != null)
    {
    header('Location: http://onlinelic.in/LICEPS/appmanager/Customer/CustomerHome');
    } */
//    curl_close($ch);
    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
    if($info['http_code'] == 301 || $info['http_code'] == 302) {
        preg_match_all('|Location: (.*)\n|U', $response, $results);
        $location = implode(';', $results[1]);
        header("Location: $location");
        exit;
    } else {
        $response = substr_replace($response, '', 0, strpos($response, '<', 0));
        echo $response;
    }
?>

2 个答案:

答案 0 :(得分:0)

您已指定您不愿意遵循此声明的任何重定向:

curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);

将值设置得更高或不指定它将使cURL跟随重定向。

答案 1 :(得分:0)

<?php
    $username="XXXXXX";
    $password="YYYYYY";
    $url="url"; 
    $capt="ZZZZZ"; 




    $postdata = "?{actionForm_userName}=".$username."&{actionForm_password}=".$password."&{actionForm_qreply}=".$capt;
    $cookie = "JSESSIONID";

    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);

    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0");
    curl_setopt($ch,CURLOPT_COOKIESESSION,true);
    curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);

    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt ($ch, CURLOPT_HEADER, 0);   
    curl_setopt ($ch, CURLOPT_REFERER, $url);
    curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
    curl_setopt ($ch, CURLOPT_POST, 1); 

      //echo $cookie;
      //echo $postdata;
echo curl_error($ch);
    $result = curl_exec ($ch);
    print($result);


curl_close($ch);


    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
    if($info['http_code'] == 301 || $info['http_code'] == 302) {
        preg_match_all('|Location: (.*)\n|U', $response, $results);
        $location = implode(';', $results[1]);
        header("Location: $location");
        exit;
    } else {
        $response = substr_replace($response, '', 0, strpos($response, '<', 0));
        echo $response;
    }  

?>