XHanch Studio Log in | Register | Cart

Forum

[Function] Update/p...
 
Notifications
Clear all

[Function] Update/post your Facebook status using PHP

1 Posts
1 Users
0 Likes
11.8 K Views
XHanch
(@xhanch-alt)
Posts: 2105
Member Admin
Topic starter
 

Here is an alternative for those who want to post/update status using PHP script. For your inforamtion, you can also update your status via email.

<?php
    //by  : Xhanch Studio
    //URL  : http://forum.xhanch.com/index.php/topic,42.0.html

    function fb_status_post($user, $pass, $status){   
        //Log in to Facebook
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, ' https://login.facebook.com/login.php?m&next=http://m.facebook.com/home.php');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, 'email='.$user.'&pass='.$pass.'&login=Log In');
        curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
        curl_setopt($ch, CURLOPT_COOKIEJAR, getcwd().'/fb_cookie.tmp');
        $raw = curl_exec($ch);
        curl_close($ch);
   
        //Checking verification result
        if(strpos($raw, 'action="/a/home') === false)
            return 'Cannot log in';

        //Determining post URL and required parameters
        $post_url = substr($raw, strpos($raw, 'action="/a/home') + 8);
        $post_url = substr($post_url, 0, strpos($post_url, '"'));
        $post_url = ' http://m.facebook.com'.$post_url;
        $fb_dtsg = substr($raw, strpos($raw, 'name="fb_dtsg"'));
        $fb_dtsg = substr($fb_dtsg, strpos($fb_dtsg, 'value=') + 7);
        $fb_dtsg = substr($fb_dtsg, 0, strpos($fb_dtsg, '"'));   
        $post_form_id = substr($raw, strpos($raw, 'name="post_form_id"'));
        $post_form_id = substr($post_form_id, strpos($post_form_id, 'value=') + 7);
        $post_form_id = substr($post_form_id, 0, strpos($post_form_id, '"'));

        //Post your status 
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $post_url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, 'fb_dtsg='.$fb_dtsg.'&post_form_id='.$post_form_id.'&status='.$status.'&update=Share');
        curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
        curl_setopt($ch, CURLOPT_COOKIEFILE, getcwd().'/fb_cookie.tmp');
        curl_setopt($ch, CURLOPT_COOKIEJAR, getcwd().'/fb_cookie.tmp');
        curl_setopt($ch, CURLOPT_REFERER, ' http://m.facebook.com/home.php?refid=0');
        $raw = curl_exec($ch);
        curl_close($ch);

        return true;
    }

    //Example of usage
    echo fb_status_post('test@example.com', '1234', 'test status');
?>
 
Posted : 09/03/2011 1:59 am
Share:

× Close Menu