Hi,
I've been trying to teach myself PHP and have been following Smaxor's excellent tutorials at Scraping and Posting your way to money on the Internet - Oooff.com. I have tried to apply what I learnt there to create a script to log into Wordpress and make a new post.
The script is logging into Wordpress fine but I'm having trouble getting it to submit the "post-new.php" form. I worked out there are two values (wpnonce and tempid) that I needed to scrape from the page to submit with the form. I've been able to do this successfully but the script still just populates the "Title" and "Content" fields but doesn't actually submit.
Any ideas on what I am doing wrong? I have done all kinds of google searches to try to work out what I might be missing but can't find anything so hopefully someone here can lend a hand.
Thanks heaps in advance. Below is an excerpt from my code:
I've been trying to teach myself PHP and have been following Smaxor's excellent tutorials at Scraping and Posting your way to money on the Internet - Oooff.com. I have tried to apply what I learnt there to create a script to log into Wordpress and make a new post.
The script is logging into Wordpress fine but I'm having trouble getting it to submit the "post-new.php" form. I worked out there are two values (wpnonce and tempid) that I needed to scrape from the page to submit with the form. I've been able to do this successfully but the script still just populates the "Title" and "Content" fields but doesn't actually submit.
Any ideas on what I am doing wrong? I have done all kinds of google searches to try to work out what I might be missing but can't find anything so hopefully someone here can lend a hand.
Thanks heaps in advance. Below is an excerpt from my code:
PHP:
///put new post page into $data
$url1 = "http://mysite.com/wp-admin/post-new.php?";
$ch1 = curl_init($url1);
curl_setopt($ch1, CURLOPT_COOKIEJAR, “cookies.txt”);
curl_setopt($ch1, CURLOPT_COOKIEFILE, “cookies.txt”);
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 10);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
echo curl_exec($ch1);
$data = curl_exec($ch1);
curl_close($ch1);
///scrape temp id
$regex = "/temp_ID' value='(.+?)'/";
preg_match($regex,$data,$match);
$tempid = $match[1];
///scrape wpnonce
$regex = '/wpnonce" value="(.+?)"/';
preg_match($regex,$data,$match2);
$wpnonce = $match2[1];
///submit a post
$url2 = "http://mysite.com/wp-admin/post-new.php?";
$post2 = "_wpnonce=$wpnonce&_wp_http_referer=%2Fwp-admin%2Fpost-new.php&user_ID=1&action=post&originalaction=post&post_author=&post_type=post&temp_ID=$tempid&newcat=&advanced_view=1&comment_status=open&ping_status=open&post_password=&post_name=&post_status=draft&mm=3&jj=25&aa=2008&hh=12&mn=13&ss=58&post_title=Testing123&content=Testing123&post_pingback=1&prev_status=draft&tags_input=&publish=Publish&referredby=redo&excerpt=&trackback_url=&metakeyinput=&metavalue=";
$ch2 = curl_init($url2);
curl_setopt($ch2, CURLOPT_COOKIEJAR, “cookies.txt”);
curl_setopt($ch2, CURLOPT_COOKIEFILE, “cookies.txt”);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, 10);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $post2);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
echo curl_exec($ch2);
curl_close($ch2);