102 thoughts on “PHP cURL Facebook status update working example!

  1. Nice script! But I cannot figure out how to post to one of my groups.
    its wall.php instead of home.php
    and even trying with the form id of the form from the mobile version of the group site seems not to work.
    did you try to do this yet?

    • Yes, i have tried to post to my friend and to a Facebook page, here are some lines that should be changed:

      curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/yourpage/');
      preg_match("/<form method=\"post\" action=\"\/a\/wall.php(.*)\">/U", $buf, $formaction);
      $postdata['message'] = $status;
      $postdata['post'] = 'Post';
      curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/a/wall.php'.$formaction[1]);

      I’ll submit the whole solution soon, probably tomorrow!

      Best regards

    • What exactly do you want to do?

      Do you want to update your Facebook application’s page (http://apps.facebook.com/jokonardi) or perhaps you meant http://www.facebook.com/jokonardi?

      If you want to update your app’s page then download the file called fb_page.php above and change the url to your page’s url.

  2. Hi,

    I have tried the script with debug and all seems ok but nothing happens when I log-in to facebook, also I tried fb_page.php to update that but they have changed the page names to profile.php?id= and i tried putting that in but it doesn’t work also.

    I am not getting any errors in the debug, cookies are being created in the folder location… ANY IDEAS PLEASE?

    • ignore the bit about page name its because I didn’t have a user name set I have done that now, but still nothing happens… ?!?! :(

      • Hey,

        Thanks for your reply, here is the out:

        [+] Sending GET request to: http://m.facebook.com/ [+] Sending POST data to: https://login.facebook.com/login.php?m=m&refsrc=http://m.facebook.com/&fbb=r7ef20245&refid=8 Array ( [post_form_id] => 43b46ef0a4ff194420a6af0d4f6f33a5 [charset_test] => €,´,€,´,水,Д,Є [email] => deej%40gbforklfits.org [pass] => pass [login] => Log+in ) [+] Fetching http://m.facebook.com/gbforklifts [+] Sending POST data to: http://m.facebook.com/a/wall.php Array ( [charset_test] => [fb_dtsg] => [post_form_id] => [message] => whatever [post] => Post ) [+] Logging out: http://m.facebook.com/logout.php

        Hope you can help. :D

        • I think the problem is because your “page” is actually a user profile. So try the same thing with fb_small.php or fb_big.php instead of fb_page.php!

          Best regards!

  3. i try this file fb_page.php but if i insert url in status, security check (captcha) is required. image captcha and submit can be error, how i can fix that??

    thank you very much…

  4. Hi,

    I tried your script you had posted here dated 29th dec has facebook changed form data again as it does not seem to log in and post status i checked the cookie and thats written to the file. Is it still working for you?

    • I tested the script posted here (the smaller version) and it works. Perhaps you should try the bigger (fb_big.php) version and post your debug info.

      I’ll be glad to help you but i need more info…

      Best regards

  5. Greetings … .. :)
    bang want to ask, how to do post a comment + article to a facebook wall … .???? such as a passing comment detik.com facebook …
    thanks … ..

  6. Hey,

    I tried using the fb_small.php file but it doesn’t work for me, and so I tried to use the fb_big.php file but it also isn’t working. I keep getting undefined offset: 1 errors (on lines 118, 119, 120, 128, and 135) after the “Fetching http://m.facebook.com/home.php “. It seems to be returning the $chartest, $dtsg, $formid, and $formaction arrays as empty. Am I doing something wrong here?


    • Did you follow this?

      - Enter a correct email and password,
      - have CURL extension with SSL support installed,
      - have read/write permissions in current directory.

      Unefined offset means that it did not get the requires parameters from the page, it usually means that there is an error page or no page. Do you have safe mode enabled?

      • It works for me… I can’t think of anything right now… If you know how, can you please check your POST status form parameters on http://m.facebook.com in the source code?

        Mine looks like this:

        <form method="post" id="composer_form" action="/a/home.php?refid=7&ref=logo"> <input type="hidden" name="fb_dtsg" value="(.*)" autocomplete="off"/> <input type="hidden" name="post_form_id" value="(.*)"/> <input type="hidden" name="charset_test" value="€,´,€,´,水,Д,Є"/> ... <input type="submit" value="Share" class="btn btnC" name="update"/>

        • Thanks for the reply – mine looks like

          Email address or phone number:Password:

          Which looks to match the pattern. Have also added further outputs to check it’s matching and looks ok to me.

          • Sorry – can’t seem to work out how to quote html in reply so here it is without proper tags…

            form method=”post” action=”https://login.facebook.com/login.php?m=m&refsrc=http%3A%2F%2Fm.facebook.com%2F&refid=8″

            input type=”hidden” name=”lsd” autocomplete=”off”

            input type=”hidden” name=”post_form_id” value=”919fccea7b4aa82d1da9b0937e0e0fbb”

            input type=”hidden” name=”charset_test” value=”€,´,€,´,水,Д,Є”


            input type=”submit” value=”Log in” class=”btn btnC” name=”login”

    • Yes, it is possible either by analyzing the response from your POST request or to GET the profile page again and see if it contains your status.

  7. Why does the Facebook hides the API from us? Twitter has a nice API (OAuth is a bit complicated, but there are some libs now). Why we have to bother with some mini-bots?

    • Facebook does not hide the API, it’s just not as simple. Read about their API: http://developers.facebook.com/.

      But, if you wan’t to use Facebook’s API to update your status you have to create an application that has full permissions from you (offline access, publish…) and then you can control you statuses via that application. So, it can be done, but it’s more difficult.

  8. Hi!! Super nice job!
    Maybe you can help me: I have an application and I need to obtain code and access_token with php and curl


    - login: ok (with your code)
    - obtain code and access_token: to do
    - post what I want: ok (with access token I can do it directly from a script like this
    curl -F ‘access_token=……’ \
    -F ‘message=TEST’ \
    -F ‘source=@result.jpg’ \
    https://graph.facebook.com/ID_group or user/photos)

    can you help me?! (:

  9. Keep getting the following error….I dont know what else to do…My friend runs it from Ubuntu 10.10 and seems to work perfectly..I have put my email and password and the new status…I gave read/write permission and seems to work to..It creates the cookie.txt but i am not sure what happens after that… I checked the status form parameters http://m.facebook.com and i have the same as yours..Really dont know what is going wrong..Any ideas or suggestions how to resolve this or any mistake i might doing..? I didnt change anything from your code i even download it again but i am getting the same error again again..I tried both big and small fb and they produce the same error….Is there any possibility to be a problem with apache or php configuration(i have safe_mode off)?..Dont know what i am doing wrong…Please i need somebodys’ help….

    [+] Sending GET request to: http://m.facebook.com/ [+] Sending POST data to: https://login.facebook.com/login.php?m=m&refsrc=http://m.facebook.com/&refid=8 Array ( [post_form_id] => 0948b59ded9811748d70b77d4fb4d9ad [charset_test] => €,´,€,´,水,Д,Є [email] => (myemail) [pass] => (mypassword) [login] => Log+in ) [+] Fetching http://m.facebook.com/home.php
    Notice: Undefined offset: 1 in C:\websites\fb_big.php on line 120

    Notice: Undefined offset: 1 in C:\websites\fb_big.php on line 121

    Notice: Undefined offset: 1 in C:\websites\fb_big.php on line 122

    Notice: Undefined offset: 1 in C:\websites\fb_big.php on line 130

    Notice: Undefined offset: 1 in C:\websites\fb_big.php on line 137
    [+] Sending POST data to: http://m.facebook.com/a/home.php Array ( [charset_test] => [fb_dtsg] => [post_form_id] => [status] => Finally+Fixed [update] => Share ) [+] Logging out: http://m.facebook.com/logout.php

    • I’m afraid there is something wrong with your login procedure… Perhaps you have other security options like typing your location or so on, because it looks to me the script cannot get to your home page.

      I hope we resolve this…

  10. I am an admin for a fan page that I did not create. I have no problems posting to the fan page from a regular browser.

    My username and password are correct and the permissions on my folder allow read and write access.

    I have tried using fb_page.php and it does not seem to be posting to the fan page or throwing back an error. Am I using the correct file or is this not meant for this purpose. It is creating “cookie.txt” but no results.

    I have been struggling with this situation and any help you can give would be much appreciated.


  11. Hi There,

    I have to say that you save my day and probably one or two more days and nights !

    I’m not a php developer, just a handy guy turning around with some peace of code … I did read thousands of OAuth and other cURL lines of codes, trying during three days to get something out of it …. Some where working, but always requesting tokens, key, authorization and actions …

    And I find your site and code … Working perfectly.

    Thank you for sharing this code.


  12. Facebook just implemented device naming to mobile logins too, so if you have the option to name your device at each login set, it will not work at the moment, but i will fix it soon. You can temporarily disable this feature on Facebook though.

    • Have you had any progress with the device naming? Y can’t seem to get it to work. I post all parameters, hidden and not, and it redirects me to the Login page again saying I haven’t singed in…

  13. Hi,
    I used your code. It was working perfectly 3 weeks ago, but it stop working now. I was wondering if facebook has changed something or there is something wrong on my side.

    Also I want to post an image along with message. Is that possible in this code ? If yes, please tell me how.

    I am trying to login and posting using Flash, without using browser, and your code was working fine.

    Thanks a lot.

    • @Sam

      Facebook changed the login form, but i fixed it now. Tell me if it works.

      Posting images is not yet implemented, I’ll do it sometime in the future…

  14. hi,

    Thanks. I manage to log in, now I want to retrieve following page in subsequent curl, but it’s failing.


    I change code as per below,
    //curl_setopt($ch, CURLOPT_URL, ‘http://m.facebook.com/’.$page);
    curl_setopt($ch, CURLOPT_URL, ‘http://m.facebook.com/grouphome.php’);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); // follow redirects recursivel

    it didn’t work (tried with FOLLOWLOCATION 1 and 0)

    • @jigs
      Did you specify your cookie file?

      curl_setopt($ch, CURLOPT_COOKIEFILE, “cookie.txt”);
      curl_setopt($ch, CURLOPT_USERAGENT, “Mozilla/5.0″); //user agent isn’t a bad idea either

  15. Thanks a lot. It is working. The only thing left is image posting. I will be waiting for the update regarding this.

    Thanks again.

  16. When I run this script nothing happens, when I login to my account normal, I get an error saying someone logged in from a location that is unrecognized… and my account is locked. When I proceed to allow the location, the status isnt posted. How do I get around this, aside from running the script locally?

    • I never had such problems… Did you set up extra security settings on Facebook like location checking? Try to normally login with a browser via the remote location and Facebook will hopefully add it to known devices…

    • If what you are looking for isn’t possible with the official API or Mobile version, i’d suggest using some libraries for parsing HTML forms to save you some time while programming… The normal web version of Facebook uses a lot of Ajax and form parameters… Good luck

  17. Hi, Admin.
    Thanks for your posting this source code. good job.
    what about if i want to post / share link to my profile.
    please help.


  18. Thanks for this code.

    For the record had to add this line to make it works (since step 2 log in)

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    Looks like some of your reader get the same error as me (white page), they coud try to add this line, works for me.

  19. Hi, I am trying to incorporate this in to my web site. My client has an admin area where he dynamically updates his web page. When he is done I want my client to be able to click an “Update Facebook button” which will run your code.
    When I run your code it works great and updates my status, but I always takes me to the facebook mobile login screen. What do I need to change to have the script login, update the status, logout and then post on admin page below the button “status updated”.

    Thanks in advance for your help.

  20. I have to update post in official facebook page (Eg: m.facebook.com/pages/Test-Page/183568008408878).
    Could you please let me know where the changes needs to be done in your code? Could you please reply me soon?

    Thanks in Advance

  21. Hi,
    I am using your code originally posted,with a few modifications, and it works perfect for posting a status up date to my profile. What I need to do now is be able to post to a Page I administer. I have tried changing the the home.php to my page id and various other things but I have not had any success.

    Your help would be greatly appreciated


    Here is my code I am using that works.



    * PHP Curl status update script
    * @since Sep 2010
    * @version 1.0
    * @link http://360percents.com/posts/php-curl-status-update-working-example/
    * @author Luka Pušić

    * Required parameters

    require_once (‘temp.php’); // php that creates the status update info

    $status = ‘New Rates: ‘ . “\n” . $Update . “….” . “\n\n”;
    $status= $status . ‘More info.’;

    $email = ‘me@hotmail.com’;
    $pass = ‘*********’;

    * check if update is empty if not Call the update function with your email, password and status parameters.
    if ($Update !=”")
    update(urlencode($email), urlencode($pass), $status);

    function update($email, $pass, $status) {
    * Optional parameters
    $uagent = ‘Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)’;
    $cookies = ‘cookie.txt’;

    * prepare status (Facebook allows only 420 chars)
    /* if (strlen($status) > 419) {
    $status = urlencode(substr($status, 0, 419));
    echo “[*] Status was stripped to 420 characters!\n\n”; } else {
    $status = urlencode($status);

    function postify($arr) {
    $fields_string = ”;
    foreach ($arr as $key => $value) {
    $fields_string .= $key . ‘=’ . $value . ‘&’;
    return rtrim($fields_string, ‘&’);

    * GET: http://m.facebook.com/
    * Parse the webpage and collect login parameters
    * (chartest, lsd, formaction).
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
    curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
    curl_setopt($ch, CURLOPT_URL, “http://m.facebook.com/”);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $buf = curl_exec($ch);

    /*echo “\n[+] Sending GET request to: http://m.facebook.com/\n\n”;*/

    preg_match(“/<form method=\"post\" class=\"mobile-login-form\" id=\"login_form\" action=\"(.*)\"/U", $buf, $formaction);
    urlencode(preg_match("//U”, $buf, $chartest));
    //preg_match(“//U”, $buf, $lsd);
    preg_match(“//U”, $buf, $formid);


    * LOGIN: POST to facebook login form (formaction) with previously
    * collected parameters lsd, chartest, email, pass and login.
    $postdata = array(
    ‘lsd’ => ”,
    ‘post_form_id’ => $formid[1],
    ‘charset_test’ => $chartest[1],
    ‘email’ => $email,
    ‘pass’ => $pass,
    ‘ajax’ => ’0′,
    ‘width’ => ’0′,
    ‘pxr’ => ’0′,
    ‘gps’ => ’0′,
    ‘version’ => ’1′,
    ‘login’ => ‘Log+in’

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
    curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
    curl_setopt($ch, CURLOPT_URL, $formaction[1]);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, postify($postdata));

    $buf = curl_exec($ch);
    /*echo $buf;

    echo “[+] Sending POST data to: ” . html_entity_decode(urldecode($formaction[1])) . “\n”;
    echo “\n\n”;*/

    * Fetch facebook.com/home.php to Collect parameters from the form which
    * updates status (formaction, chartest, dtsg, formid). This step is
    * important because we want to avoid using CURLOPT_FOLLOWLOCATION.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
    curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
    curl_setopt($ch, CURLOPT_URL, ‘http://m.facebook.com/home.php’);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $buf = curl_exec($ch); //execute the curl command

    /*echo “[+] Fetching http://m.facebook.com/home.php\n\n”;*/

    preg_match(“//U”, $buf, $formaction);
    preg_match(“//U”, $buf, $chartest);
    preg_match(“//U”, $buf, $dtsg);
    preg_match(“//U”, $buf, $formid);


    * 3. UPDATE STATUS: Use previously collected form data to send a post query
    * which will update our status.
    $postdata = array(
    ‘charset_test’ => $chartest[1],
    ‘fb_dtsg’ => $dtsg[1],
    ‘post_form_id’ => $formid[1],
    ‘status’ => $status,
    ‘update’ => ‘Share’

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
    curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
    curl_setopt($ch, CURLOPT_URL, ‘http://m.facebook.com/a/home.php’ . $formaction[1]);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, postify($postdata));

    $buf = curl_exec($ch);

    /*echo “[+] Sending POST data to: http://m.facebook.com/a/home.php” . html_entity_decode($formaction[1]) . “\n”;
    echo “\n\n”;*/

    * Something will probably appear in $buf if it fails :)
    if (strlen($buf) > 0) {
    /*echo “[ERR] Status update response:$buf\n\n”;*/


    * Logout, end funtion update and return.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
    curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
    curl_setopt($ch, CURLOPT_URL, ‘$_SERVER["PHP_SELF"]‘);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);


    /*echo “[+] Logging out: http://m.facebook.com/logout.php\n\n”;*/

    return 0;

  22. I have observed facebook form structure after running the script and found the structure is very different from the script one. Hope you are gonna update soon.

  23. Improved Facebook bot | 360 percents

  24. Fatal error: Call to a member function getAttribute() on a non-object in C:\wamp\www\LFB\test1.php on line 43

  25. hi,
    any update for

    Fatal error: Call to a member function getAttribute() on a non-object in C:\wamp\www\fb\fb_bot.php on line 43


  26. resplacing in function grab_home():

    curl_setopt($ch, CURLOPT_URL, ‘https://m.facebook.com/’);


    curl_setopt($ch, CURLOPT_URL, ‘http://m.facebook.com/login.php?next=http%3A%2F%2Fm.facebook.com%2Fhome.php%3Fm_sess’);

    worked for me.

  27. Is there a newer Version of this script? I had this error: Fatal error: Call to a member function getAttribute() on a non-object in /volume1/web/test.php on line 43 // Can someone help me?

  28. I was doing something similar to try and scrape a facebook profile page on mysite.com, if the user give me his facebook.com/john.smith.123456 url. The user is already logged in, so if HE opened a new window with this url, he would get his profile. Since the user is logged in, a Liked Facebook Like button will be Greyed on mysite.com. If mysite.com tries to curl that profile url, however, it gets the not-logged-in-Is-This-The-John-Smith-You-Mean?-page. mysite.com does not know the user’s login and password, though has some access to facebook to grey the Like… Is there any way to scrape the real profile page? Anyone?

  29. I’m not sure exactly what this script is supposed to do? Can someone tell me?
    Does this click a facebook like without the user knowing?

  30. Hello can i help me to code a function that send a user or friend a message?

    I will use this for my little family reminder :) thanks

  31. PHP Curl status update script | jerryriadyblog

  32. If you are updating multiple profiles status’ with this script, you will need to modify the cookies part as it will re-use the values stored in the cookie, and therefore will not take a different email and password.

    Works well thanks to the developer!

  33. script bot auto update fbk | jerryriadyblog

  34. Hi, Thank You for this snippet :) there’s one small problem I went into which is that this function works with localhost (wamp) while it doesn’t work on my server (VPS) running lamp server (everything work including php5 and cURL extension on ubuntu :/ it gives error:
    “This is fucking shit:”

  35. This script is amazing! Thank you!

    Is there a way to keep the session open and the user to navigate on facebook using normally the profile?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>