2014-10-21 5 views
0

나는이 문제에 대한 여러 가지 방법과 접근법을 모두 시도해 왔으며 나는 혼란 스럽다. PHP로 www.senderscore.org에 로그인하려고합니다. 사이트의 로그인은 색인 페이지의 게시 양식입니다. 몇 가지 IP를 조회하고 정기적으로 정보를 기록해야하므로이 작업을 수행해야합니다. 나는 곱슬 곱슬하게 게시하려고 시도했지만 운이 없었습니다. 모든 시도는 로그인하지 않은 것처럼 페이지를 반환합니다. 누군가 코드 스 니펫으로 도울 수 있다면 대단히 감사하겠습니다.php curl login 원격 서버

편집 : 최신 시도 코드 블록. 이것은 클래스 함수 내부의 코드입니다.

$username= $this->username; 
    $password= $this->password; 

    $url = 'www.senderscore.org/index.php'; 

    $fields = array(
    'email'=>$username, 
    'password'=>$password, 
    'action'=>"localLogin", 
    'Submit'=>"Sign in", 
    'remember'=>'1' 
    ); 

    $postvars=''; 
    $sep=''; 
    foreach($fields as $key=>$value) 
    { 
     $postvars.= $sep.urlencode($key).'='.urlencode($value); 
     $sep='&'; 
    } 

    $curl = curl_init(); 

    curl_setopt($curl,CURLOPT_URL,$url); 
    curl_setopt($curl,CURLOPT_POST,true); 
    curl_setopt($curl,CURLOPT_POSTFIELDS,$postvars); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);   
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 

    $data = curl_exec($curl); 

    if ($data === false) { 
     $data = curl_error($curl); 
    } 
    curl_close($curl); 

    return $data; 
+0

브라우저에서 전송되는 요청을 보았습니까? – PeeHaa

+0

php 내에서 사용중인 CURL 호출을 제공 할 수 있습니까? – commanderZiltoid

+0

코드를 게시 한 후 https : //가 URL에없는 것으로 나타났습니다. 이 문제가 내 견과를 몰고 간다 ...> – James

답변

0

이 스크립트를 살펴 보려면 게시와 함께 작동해야합니다. 테스트를 거치지 않았습니다.

$username = 'your_username'; 
$password = 'your_password'; 
$loginUrl = 'http://www.path-to-login.com/login/'; 

//init curl 
$ch = curl_init(); 

//Set the URL to work with 
curl_setopt($ch, CURLOPT_URL, $loginUrl); 

// ENABLE HTTP POST - this is important in your case 
curl_setopt($ch, CURLOPT_POST, 1); 

//Set the post parameters - make sure to match username and password 
curl_setopt($ch, CURLOPT_POSTFIELDS, 'user='.$username.'&pass='.$password); 

//Handle cookies for the login 
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); 

//Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL 
//not to print out the results of its query. 
//Instead, it will return the results as a string return value 
//from curl_exec() instead of the usual true/false. 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

//execute the request (the login) 
$store = curl_exec($ch); 

//the login is now done and you can continue to get the 
//protected content. 

//set the URL to the protected file 
curl_setopt($ch, CURLOPT_URL, 'http://www.site-logging-into.com/protected/file.zip'); 

//execute the request 
$content = curl_exec($ch); 

//save the data to disk 
file_put_contents('~/file.zip', $content);