maximviper
BANNED
- Oct 25, 2010
- 338
- 87
hello,
I am trying to post article sto my worpress blogs using cURl ,i looked internet and found this code but its not working.. can some please help me fix this code ?
i enabled xmlrpc in my wordpress blog.but still i m not able to post.
I am trying to post article sto my worpress blogs using cURl ,i looked internet and found this code but its not working.. can some please help me fix this code ?
PHP:
<?php
function curlRemotePostToWordPress($url, $login, $pass, $postTitle, $postCats, $postContent) {
echo "<BR> $pass <BR>";
// Remote post url
$rpcUrl = rtrim($url, '/').'/xmlrpc.php';
// Categories for the post
$categories = explode(',', $postCats);
// Post xml
$xml = '<title>'.$postTitle.'
<category>'.$categories.'</category>
< ![CDATA[ '.$postContent.' ]]>';
// Build request
$params = array('', '', $login, $pass, $xml, 1);
echo "<BR> $params <BR>";
$request = xmlrpc_encode_request('blogger.newPost', $params);
echo $request;
// Send the request
try {
$ch = curl_init();
// cUrl configuration
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $rpcUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
// Execution
curl_exec($ch);
curl_close($ch);
return true;
} catch (Exception $e) {
return false;
}
}
$url="www.xxxxxxxx.com";
$login="admin";
$pass="passwrd";
$postTitle="hello word new";
$postCats="latest";
$postContent="This is my new test post";
echo curlRemotePostToWordPress($url, $login, $pass, $postTitle, $postCats, $postContent);
?>
i enabled xmlrpc in my wordpress blog.but still i m not able to post.