Publish a post on your WordPress blog using PHP + cURL
I think I should name my blog “Web Bot source codes” :P Lolz , today I will be posting something similar called WPBot – Wordpress bot. The PHP code which will publish a post on your post using cURL.This PHP is dependent on class file class.XMLHttpRequest.php ( You can get it here ).You can use this function for various things like publishing of scores , news , jokes etc on your blog . Use cron job method of automated things as used in Twitter Bot.
Source Code
<?php
include("class.XMLHttpRequest.php");
//URL of the wordpress blog
$link="http://localhost/chetanim/newwp/";
//Logins
$username="admin";
$password="admin";
//Title and body
$title=time();
$body="Hello ! World";
//Common setting
$setting=array();
$setting['User-Agent']="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.17) Gecko/2009122116 Firefox/3.0.17 GTB5";
$setting['Login-File']="wp-login.php";
$setting['Accept']="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$setting['Accept-Language']="en-us,en;q=0.5";
$setting['Accept-Charset']="ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$setting['Content-Type']="application/x-www-form-urlencoded; charset=UTF-8";
$setting['Reffer']="{$link}wp-login.php?redirect_to=http%3A%2F%2Flocalhost%2Fchetanim%2Fnewwp%2Fwp-admin%2F";
//Getting logged in to the blog and getting cookies in var
$req=new XMLHttpRequest();
$req->open("POST","{$link}{$setting['Login-File']}");
$req->setRequestHeader("Host","localhost");
$req->setRequestHeader("User-Agent",$setting['User-Agent']);
$req->setRequestHeader("Accept",$setting['Accept']);
$req->setRequestHeader("Accept-Language",$setting['Accept-Language']);
$req->setRequestHeader("Accept-Encoding","gzip,deflate");
$req->setRequestHeader("Accept-Charset",$setting['Accept-Charset']);
$req->setRequestHeader("Referer",$setting['Reffer']);
$req->send("log=".urlencode($username)."&pwd=".urlencode($password)."&wp-submit=Log+In&redirect_to=".urlencode($link)."wp-admin%2F&testcookie=1&");
$responseText=$req->responseText;
$cookie=$req->getResponseHeader('Set-Cookie');
$req->close();
//Cleaning and arranging cookie properly
$cookie=explode(";",$cookie);
$cookie_part1=explode(", ",$cookie[1]);
$cookie_part1=$cookie_part1[1];
$cookie_part2=str_replace("httponly, ","",$cookie[3]);
$cookie_part3=str_replace("httponly, ","",$cookie[5]);
$cookie=str_replace(" ",'',$cookie_part1.";".$cookie_part2.";".$cookie_part3.";");
//Posting the topic
$req=new XMLHttpRequest();
$req->open("POST","{$link}wp-admin/post.php");
$req->setRequestHeader("Host","localhost");
$req->setRequestHeader("User-Agent",$setting['User-Agent']);
$req->setRequestHeader("Accept",$setting['Accept']);
$req->setRequestHeader("Accept-Language",$setting['Accept-Language']);
$req->setRequestHeader("Accept-Encoding","gzip,deflate");
$req->setRequestHeader("Accept-Charset",$setting['Accept-Charset']);
$req->setRequestHeader("Content-Type",$setting['Content-Type']);
$req->setRequestHeader("X-Requested-With","XMLHttpRequest");
$req->setRequestHeader("Referer","{$link}wp-admin/");
$req->setRequestHeader("Cookie",$cookie);
$request="post_title=".urlencode($title)."&content=".rawurlencode($body)."&tags_input=&action=post-quickpress-publish&quickpress_post_ID=0&_wpnonce=647ecf8dea&_wp_http_referer=" .urlencode($link."/wp-admin")."&";
$req->send($request);
$responseText=$req->responseText;
preg_match('/<a href="(.*)">View post<\/a>/',$responseText,$postlink);
//The link of the post
$postlink=$postlink[1];
echo
$postlink;
?>
Do Report Bugs and comment your new ideas or creativity over here.
Regards,
Chetan Mendhe
SHashank Amin 11:48 am on February 6, 2010 Permalink |
Great … TFS
chetanweb 3:48 pm on February 6, 2010 Permalink |
Welcome !!
Publish a post on your WordPress blog using PHP and cURL « Silver Acids - THE RISE OF TECHNOLOGY 12:29 pm on February 6, 2010 Permalink |
[...] quite new to your ears.You heard it Right its a new bot developed by chetan mendhe(chetanweb.com).It is something agnate alleged WPBot – Wordpress bot. The PHP code which will broadcast a column [...]
ace 8:56 am on February 7, 2010 Permalink |
tfs
abhi 8:57 am on February 7, 2010 Permalink |
awesome work
Женя 1:54 am on February 12, 2010 Permalink |
Для коллекции прогодится.
Hesyembetle 10:44 pm on February 18, 2010 Permalink |
http://www.ganar-dinero-ya.com/ganardinero.jpg
La mejor web sobre ganar dinero
Hemos hallado la mejor pagina web en internet de como ganar dinero internet. Como fue de utilidad a nosotros, tambien les puede ser de interes para ustedes. No son unicamente formas de ganar dinero con su pagina web, hay todo tipo de metodos de ganar dinero en internet…
http://www.ganar-dinero-ya.com/dinero.jpgTe recomendamos entrar a Ganar dinerohttp://www.ganar-dinero-ya.com/dinero.jpg
Hesyembetle 10:55 pm on February 18, 2010 Permalink |
http://www.ganar-dinero-ya.com/ganardinero.jpg
Necesitas ganar dinero y no sabes que hacer
Hemos hallado la mejor pagina web en internet de como ganar dinero internet. Como fue de interes para nosotros, tambien les puede ser de interes para ustedes. No son unicamente formas de ganar dinero con su pagina web, hay todo tipo de formas para ganar dinero en internet…
http://www.ganar-dinero-ya.com/dinero.jpgTe recomendamos entrar a Ganar dinero desde casahttp://www.ganar-dinero-ya.com/dinero.jpg
Catrina Schoenberg 11:41 pm on February 24, 2010 Permalink |
Great way to explain it. Can’t say more than to appreciate what you are penned down. can you show how to grab your rss feed? I couldn’t find how.
WP Themes 1:50 pm on March 18, 2010 Permalink |
Amiable fill someone in on and this fill someone in on helped me alot in my college assignement. Thanks you for your information.
steven 8:49 pm on April 3, 2010 Permalink |
this error like This "Your attempt to add this post has failed.
Please try again."
please help me ..
thank
chetanweb 2:22 pm on May 15, 2010 Permalink |
enter your wordpress url and Admin logins properly in the script.It will work for sure