2012-10-20 7 views
0

나는 curl로 phpbb 3.0.10에 대한 자동 로그인 봇을 만들려고합니다. 포럼에서 "귀하가 성공적으로 로그인되었습니다."를 반환합니다. 하지만 그 후 사이트의 다른 페이지로 이동하여 file_get_contents가있는 소스를 얻으려고하거나 심지어 index.php로 리디렉션 할 페이지를 기다리는 경우에도 로그인하라는 메시지가 나타납니다. 당신은 쿠키를 설정해야phpbb3 컬 로그인

<?php 
$urltopost = "http://www.site.com/phpbb3eng/ucp.php?mode=login"; 
$fget = file_get_contents($urltopost); 
$sid_a = explode('index.php?sid=',$fget); 
$sid_b = explode('"',$sid_a[1]); 
$sid = $sid_b[0]; 
$datatopost = array (
'username' => "bot", 
'password' => "123456789asd", 
'autologin' => "1", 
'viewonline' => "1", 
'redirect' => "./ucp.php?mode=login", 
'sid' => "$sid", 
'redirect' => "index.php?sid=$sid", 
'login' => "login" 
); 

$ch = curl_init ($urltopost."&sid=$sid"); 
curl_setopt ($ch, curlopt_post, true); 
curl_setopt ($ch, curlopt_postfields, $datatopost); 
curl_setopt ($ch, curlopt_returntransfer, true); 
curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (windows; u; windows nt 6.1; en-us; rv:1.9.1.2) gecko/20090729 firefox/3.5.2 gtb5'); 
$returndata = curl_exec ($ch); 
$code = $returndata; 
echo htmlspecialchars($code); //returns source with successful login 
$code2 = file_get_contents("http://www.site.com/phpbb3eng/index.php"); 
echo "<br /><br /><br />".htmlspecialchars($code2); // return login form 
?> 

답변

3

: 요점은 내가 로컬 호스트에서이 테스트를하고 있어요 있다는 것입니다 및 포럼 다른 서버에 있고 난 곱슬 곱슬 사용 그 이유는 ... 다음은 내 코드입니다. 설명서를 확인하십시오 : 물론 http://php.net/manual/en/function.curl-setopt.php

curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); 
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); 

당신이 cookie.txt 파일이 존재하는지 확인해야하고 쓰기 권한이 있는지 확인하십시오.

+0

정말로 나를 도와주세요! – ragis