2011-06-15 7 views
3

메신저에 컬이 몇 가지 문제가 있습니다. 해결 방법을 모릅니다.CURLOPT_FOLLOWLOCATION을 (를) 활성화 할 수 없습니다.

아이디어는 사용자 이름과 PW를 가져 와서 외부 웹 페이지에 게시하는 것입니다. 여기

코드입니다 : 여기

$ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://sso.uc.cl/cas/login?service=https://portaluc.puc.cl/uPortal/Login"); // URL to post 
    curl_setopt ($ch, CURLOPT_POST, 1); 
    curl_setopt ($ch, CURLOPT_POSTFIELDS,   "username=$usuario&password=$pw"); 
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
    $result = curl_exec($ch); // runs the post 
    curl_close($ch); 
    echo "Reply Response: " . $result; // echo reply response 

오류입니다 : 그 오류 후

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/th000862/public_html/encuesta/login2.php on line 10 

는, 사용자는 외부 웹 페이지에 로그인되지 않습니다.

+0

, PEAR Http_Request2 또는 젠드/호드 또는 다른 HTTP 유틸리티 구현을 시도 :

이 시도. – mario

답변

6

이 오류는 PHP 구성이 사용자의 위치를 ​​따르지 못하게한다는 것을 의미합니다. @mario에서 제안한대로 추가 라이브러리를 설치하지 않고도이 문제를 해결할 수있는 몇 가지 방법이 있습니다.

  • 서버를 소유하고 있거나 루트 권한이있는 경우 php.ini 파일을 변경하여 "safe_mode"를 비활성화 할 수 있습니다.
  • php_value safe_mode off과 함께 문서 루트에 .htaccess 파일을 만들 수도 있습니다.
  • ini_set('safe_mode', false);을 PHP 파일에 추가 할 수 있습니다. 위의 작품 중 어느 것도, 당신은 또한이 라인을 따라 뭔가 할 수 없었다 경우

가 :

$ch = curl_init('https://sso.uc.cl/cas/login?service=https://portaluc.puc.cl/uPortal/Login'); 

curl_setopt($ch, CURLOPT_POST, TRUE); 
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username=' . urlencode($usuario) . '&password=' . urlencode($pw)); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE); 
curl_setopt($ch, CURLOPT_NOBODY, TRUE); 
curl_setopt($ch, CURLOPT_HEADER, TRUE); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); 
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); 

$result = curl_exec($ch); 

curl_close($ch); 

// Look to see if there's a location header. 
if (! empty($result)) 
    if (preg_match('/Location: (.+)/i', $result, $matches)) 
    { 
    // $matches[1] will contain the URL. 
    // Perform another cURL request here to retrieve the content. 
    } 
3

너무을, 당신이 할 필요 를 HTTPS 프로토콜을 사용하여 페이지의 접근을 위해, 당신은 CURLOPT_SSL_VERIFYPEER을 변경해야합니다 거짓으로. 컬의 해결 방법이 작동하지 않는 경우

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
관련 문제