how to change facebook status with php


/ Published in: PHP
Save to your folder(s)

Changing Facebook Status with PHP, download the Mini Bot PHP class from the blog http://www.barattalo.it


Copy this code and paste it in your HTML
  1. //
  2. // change Facebook status with curl
  3. // Thanks to Alste (curl stuff inspired by nexdot.net/blog)
  4. public function setFacebookStatus($status, $login_email, $login_pass) {
  5. $debug = false;
  6. //CURL stuff
  7. //This executes the login procedure
  8. $ch = curl_init();
  9. curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php');
  10. curl_setopt($ch, CURLOPT_POSTFIELDS, 'email=' . urlencode($login_email) . '&pass=' . urlencode($login_pass) . '&login=' . urlencode("Log in"));
  11. curl_setopt($ch, CURLOPT_POST, 1);
  12. curl_setopt($ch, CURLOPT_HEADER, 0);
  13. //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  14. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  15. curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
  16. curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
  17. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  18. //make sure you put a popular web browser here (signature for your web browser can be retrieved with 'echo $_SERVER['HTTP_USER_AGENT'];'
  19. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12");
  20. curl_exec($ch);
  21.  
  22. //This executes the status update
  23. curl_setopt($ch, CURLOPT_POST, 0);
  24. curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
  25. $page = curl_exec($ch);
  26.  
  27. curl_setopt($ch, CURLOPT_POST, 1);
  28. //this gets the post_form_id value
  29. preg_match("/input type=\"hidden\" name=\"post_form_id\" value=\"(.*?)\"/", $page, $form_id);
  30. //we'll also need the exact name of the form processor page
  31. preg_match("/form action=\"(.*?)\"/", $page, $form_num);
  32.  
  33. curl_setopt($ch, CURLOPT_POSTFIELDS, 'post_form_id=' . $form_id[1] . '&status=' . urlencode($status) . '&update=' . urlencode("Update status"));
  34. //set url to form processor page
  35. curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com' . $form_num[1]);
  36. curl_exec($ch);
  37.  
  38. if ($debug) {
  39. //show information regarding the request
  40. echo curl_errno($ch) . '-' . curl_error($ch);
  41. echo "<br><br>Your Facebook status seems to have been updated.";
  42. }
  43. //close the connection
  44. curl_close($ch);
  45. }

URL: http://www.barattalo.it/2010/03/01/php-curl-bot-to-update-facebook-status/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.