Posts Mentioning RSS Toggle Comment Threads | Keyboard Shortcuts

  • chetanweb 11:45 am on February 6, 2010 Permalink | Reply
    Tags:   

    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

     
  • chetanweb 6:04 am on January 11, 2010 Permalink | Reply
    Tags: bot, , qoutes, twitter   

    Twitter Bot : Post Qoutes to twitter automaticly via PHP 

    I made this code for my personal use but now thought of sharing this it over here.On execution this PHP will post a tweet in your profile via twitter api . Tweet will have a beautiful quote or saying.Set this PHP execution over a cron job or scheduled jobs.

    <?php
    echo realpath("twitter.php");
    echo 
    "<br>";

    $type[0]="love";
    $type[1]="friendship";
    $type[2]="life";
    $type[3]="funny";
    $type[4]="inspirational";
    $type[5]="money";
    $type=$type[rand(0,5)];
    $curl curl_init();
    curl_setopt($curlCURLOPT_URL"http://www.quotesdaddy.com/widget/tag/$type");
    curl_setopt($curlCURLOPT_CONNECTTIMEOUT2);
    curl_setopt($curlCURLOPT_RETURNTRANSFER1);
    $q curl_exec($curl);
    curl_close($curl);
    $q=explode("&ldquo;",$q);
    $q=explode("&rdquo;",$q[1]);
    $q=$q[0];
    $username '[username]';
    $password '[password]';
    $status urlencode(stripslashes(urldecode($q)));

    if ($status) {
    $tweetUrl 'http://www.twitter.com/statuses/update.xml';

    $curl curl_init();
    curl_setopt($curlCURLOPT_URL"$tweetUrl");
    curl_setopt($curlCURLOPT_CONNECTTIMEOUT2);
    curl_setopt($curlCURLOPT_RETURNTRANSFER1);
    curl_setopt($curlCURLOPT_POST1);
    curl_setopt($curlCURLOPT_POSTFIELDS"status=$status");
    curl_setopt($curlCURLOPT_USERPWD"$username:$password");

    $result curl_exec($curl);
    $resultArray curl_getinfo($curl);

    if ($resultArray['http_code'] == 200)
    echo 
    'Tweet Posted';
    else
    echo 
    'Could not post Tweet to Twitter right now. Try again later.';

    curl_close($curl);
    }
    ?>


     
    • Shashank Amin 6:28 am on January 11, 2010 Permalink | Reply

      Oh now i came to know how does your status on onkut keeps on changing :P

      • Shashank Amin 6:28 am on January 11, 2010 Permalink | Reply

        orkut* :P

      • Shashank Amin 6:48 am on January 11, 2010 Permalink | Reply

        And could you share the script for orkut also please :(

        • chetanweb 12:00 pm on January 11, 2010 Permalink | Reply

          Thats something uniq about my profile !! :P I dont want to make it common :) Sorry

    • ace 9:52 am on January 11, 2010 Permalink | Reply

      nice thanks for the source…

    • Chetan 1:44 pm on January 21, 2010 Permalink | Reply

      I made one for facebook.com also will be posting soon ;)

      • Shashank Amin 8:07 am on January 24, 2010 Permalink | Reply

        will be waiting :)

    • Jack 10:06 am on February 14, 2010 Permalink | Reply

      looks like this script doesn’t work anymore.
      Am i missing something ?

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel