2012-08-01 6 views
0

나는 내 admin 페이지에 로그인 한 다음 rss를 제출할 PHP 스크립트를 작성해야합니다. 나는 아래의 코드로 로그인 할 수 있어요,하지만 "http://site.com/admin.php?mod=rss & 행동 = 뉴스 &에 RSS에게CURL : PHP : 제출할 수 없습니다

<?php 

function rssadd($url,$post,$post2) { 
$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.4) Gecko/2008102920 AdCentriaIM/1.7 Firefox/3.0.4'); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
curl_setopt($ch, CURLOPT_REFERER, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$result = curl_exec($ch); 
curl_close($ch); 

$ch2 = curl_init($url); 
curl_setopt($ch2, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.4) Gecko/2008102920 AdCentriaIM/1.7 Firefox/3.0.4'); 
curl_setopt($ch2, CURLOPT_POST, 1); 
curl_setopt($ch2, CURLOPT_POSTFIELDS, $post2); 
curl_setopt($ch2, CURLOPT_REFERER, $url); 
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1); 
$result2 = curl_exec($ch2); 
return $result . $result2; 

} 
    $page2 = rssadd('http://site.com/admin.php?mod=rss&action=news&id=4','subaction=dologin&username=admin&password=pass','subaction=doit'); 

echo $page2; 

?> 

HTML을 제출할 수 없습니다 id = 4 "제출할 수 없습니다.

<input type="submit" name="subaction" value="doit" class="buttons"> 

답변

0

아마도 요청간에 쿠키를 유지해야합니까? CURLOPT_COOKIEFILE'' (빈 문자열)로 설정하십시오. 또한 첫 번째 핸들을 닫고 새 핸들을 초기화하는 대신 두 번째 요청에서 동일한 컬 핸들을 사용해야합니다. 첫 번째 핸들의 옵션을 변경하고 다시 실행하십시오.

원래이 스택 오버플로 대답에서이 작업을 수행하는 방법을 배웠습니다. https://stackoverflow.com/a/5758471/638544

관련 문제