2013-10-28 72 views
0

我想使用php curl登录到一个站点,但我不熟悉csrf_token,我在我的发布数据中看到我也发送了此消息。下面是我的代码,我不能够登录 的csrf_token我的浏览器发送的:在php中使用curl登录到需要csrf_token的网站

csrf_token = 20131028152953%23%23f31508fbc631e906973451eefe8a88ce1b9270ad &名=名称&密码=传递

$name="name"; 
$password="pass"; 
$url="domain.com/login"; 
$cookie="cookie.txt"; 

$postdata = "name=".$name."&password=".$password; 

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 

echo $result; 

curl_close($ch); 
+0

'csrf_token'可以是任何东西。你必须展示它。 – DanFromGermany

回答

0

我猜csrf_token每次都在改变,你加载的网站。你应该首先加载站点,登录表单在哪里,然后在DOM csrf_token中解析,然后按照你的问题编写你的curl。