0

I need to write a php script that will login to my admin page then submit rss. I'm able to login with the code below, but can't submit the rss

 <?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;

?>

the html on "http://site.com/admin.php?mod=rss&action=news&id=4" i'm not able to submit

 <input type="submit" name="subaction" value="doit" class="buttons">
Crazy_Bash
  • 1,755
  • 10
  • 26
  • 38

1 Answers1

0

Perhaps you need to retain cookies between requests? Try setting CURLOPT_COOKIEFILE to '' (the empty string). You'll also need to use the same curl handle on both requests - instead of closing the first handle and initializing a new one, just change the options on the first one and run it again.

I originally learned how to do this from this Stack Overflow answer: https://stackoverflow.com/a/5758471/638544

Community
  • 1
  • 1
Brilliand
  • 13,404
  • 6
  • 46
  • 58