Page 1 of 1

POSTING to a wordpress blog using cURL.

Posted: Sun Feb 24, 2008 4:08 am
by loozi
~pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hey all, I just joined this great forum and I'm having some problems with my code so it'd be great if someone could give me a hand.

I'm trying to post a comment to a wordpress blog using cURL, and it's not working for some reason. Here's the code :

Code: Select all

<?php
 
$url = "http://blog.shankarganesh.com/2007/12/20/warning-a-worm-is-spreading-through-orkut/";
$post_fields = "author=username&email=blahblah@gmail.com&url=nothing.com&comment=Thanks&submit=Submit+Comment&comment_post_ID=328&subscribe=subscribe";
$agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$c_path = "C:/php/cook";
 
$ch = curl_init();
 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEFILE, $c_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $c_path);
 
$data = curl_exec($ch);
 
curl_close($ch);
 
echo $data;
 
 
?>
 
 
I just started learning PHP so.. :P


~pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: POSTING to a wordpress blog using cURL.

Posted: Sun Feb 24, 2008 4:25 pm
by John Cartwright
What is the value of $data after the curl_exec() call?

Code: Select all

 
$data = curl_exec($ch);
var_dump($data);

Re: POSTING to a wordpress blog using cURL.

Posted: Mon Feb 25, 2008 12:43 am
by jmut
just in case you missed it, there is xmlrpc build in wordpress, so you can post using it.

Re: POSTING to a wordpress blog using cURL.

Posted: Mon Feb 25, 2008 2:53 am
by loozi
Jcart wrote:What is the value of $data after the curl_exec() call?

Code: Select all

 
$data = curl_exec($ch);
var_dump($data);

It displays the websites html, I can't copy paste it here since it's too big. I tried changing the $post_fields string and the $url to the signup page, and it successfully made an account. I think the problem is " comment_post_ID=328 ". is there a way to get the comment id automatically using a php code?

Re: POSTING to a wordpress blog using cURL.

Posted: Thu Feb 28, 2008 12:41 pm
by loozi
jmut wrote:just in case you missed it, there is xmlrpc build in wordpress, so you can post using it.
can you please show me an example of how it's done? :)