2012-09-03 59 views
-2

我需要使用curl从我的网站登录到 https://login.naukri.com/nLogin/Login.php?URL=http%3A%2F%2Fjobsearch.naukri.com%2Fmynaukri%2Fjs_recommends.php登录与卷曲其他来源(eg.naukri.com)

。请帮忙。

/* 
* Data which is to submitted to the remote URL 
*/ 
$data = array(); 
$data['USERNAME'] = '[email protected]'; 
$data['PASSWORD'] = '[email protected]'; 
$data['formSubmitted']=1; 



/* 
* Prepare data for posting. That is, urlencode data 
*/ 
$post_str = ''; 
foreach($data as $key=>$val) { 
    $post_str .= $key.'='.urlencode($val).'&'; 
} 
$post_str = substr($post_str, 0, -1); 

/* 
* Initialize cURL and connect to the remote URL 
* You will need to replace the URL with your own server's URL 
* or wherever you uploaded this script to. 
*/ 
$ch = curl_init(); 
$url="https://login.naukri.com/nLogin/Login.php?msg=0&URL=http%3A%2F%2Fmy.naukri.com"; 

curl_setopt($h, CURLOPT_URL, $url); 
curl_setopt($h, CURLOPT_POST, true); 
curl_setopt($h, CURLOPT_HEADER, false); 
curl_setopt($h, CURLOPT_RETURNTRANSFER, 1); 
$result = curl_exec($h); 
+2

什么是您当前的代码和问题你正在服用的方法呢? – Fluffeh

+0

http://whathaveyoutried.com? – alfasin

回答

0

您需要设置身份验证仍然是一个Cookie Jar,和所有必填字段:

$data = array(); 
$data['userName'] = '[email protected]'; 
$data['passwd'] = 'tryingcurl'; 
$data['loginbtnUp'] = '1'; 
$data['submit_flag'] = '1'; 
$data['rand'] = microtime(true); 
$data['formSubmitted']=1; 

$post_str = ''; 
foreach($data as $key=>$val) { 
    $post_str .= $key.'='.urlencode($val).'&'; 
} 
$post_str = substr($post_str, 0, -1); 
$cookie_file = "/directory/to/cookie.txt"; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://my.monsterindia.com/login.html?rand=randck'); 
curl_setopt($ch, CURLOPT_POST, TRUE); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); 
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
$response = curl_exec($ch); 

curl_close($ch); 

echo $response; 
+0

非常感谢你......这帮了我很多 –