POSTING to a wordpress blog using cURL.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
loozi
Forum Newbie
Posts: 10
Joined: Sun Feb 24, 2008 4:04 am

POSTING to a wordpress blog using cURL.

Post 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]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: POSTING to a wordpress blog using cURL.

Post by John Cartwright »

What is the value of $data after the curl_exec() call?

Code: Select all

 
$data = curl_exec($ch);
var_dump($data);
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: POSTING to a wordpress blog using cURL.

Post by jmut »

just in case you missed it, there is xmlrpc build in wordpress, so you can post using it.
loozi
Forum Newbie
Posts: 10
Joined: Sun Feb 24, 2008 4:04 am

Re: POSTING to a wordpress blog using cURL.

Post 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?
loozi
Forum Newbie
Posts: 10
Joined: Sun Feb 24, 2008 4:04 am

Re: POSTING to a wordpress blog using cURL.

Post 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? :)
Post Reply