처음으로 cURL을 사용하고 있습니다. 사이트에 로그인해야하고 코드가 작동하지 않습니다. 도움.cURL을 사용하여 사이트 로그인
은 내가 문제 오순절 설정 쿠키
<?php
$cookie_file_path = tempnam('/tmp', 'cookie');
// Login variables
$urls = 'http://mypage.php';
$uname = 'user';
$upass = 'pass';
$unamefield = '*****';
$upassfield = '*****';
$usubmit = 'submit';
// Log into the specified website and return the cURL variable
function login($loginURL, $username, $userFieldName, $password, $passFieldName, $usubmitContent) {
// Initialize the page
$page = curl_init($loginURL);
// Set POST data
curl_setopt($page, CURLOPT_POST, 1);
$postData = $userFieldName . '=' . $username . '&' . $passFieldName . '=' . $password;
if(!empty($usubmitContent)) $postData = $postData . '&' . $usubmitContent;
curl_setopt($page, CURLOPT_POSTFIELDS, $postData);
curl_setopt($page, CURLOPT_RETURNTRANSFER, true);
// Set the location of and send the cookies
curl_setopt($page, CURLOPT_COOKIEJAR, 'cookies.txt');
// return the cURL variable for later use
return $page;
}
$page = login($urls, $unamefield, $uname, $upassfield, $upass, $usubmit);
$result = curl_exec($page);
// curl_close($page);
print $result;
$page = curl_init('http://mypage.php');
// Set the location of and send the cookies
curl_setopt($page, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($page, CURLOPT_RETURNTRANSFER, $cookie_file_path);
$result = curl_exec($page);
curl_close($page);
print $result;
?>
내가이 문제와 행운이 무엇인지보기 위해 구글이있다.
더 많은 코드와 오류 메시지를 보여주십시오. 게시 할 때 코드 태그 안에 코드를 넣어야합니다. – Banjer