Posted By

ginoplusio on 08/10/10


Tagged

web iphone service push webprogramming


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

hobbyman
Priestd09


How to send push notification to iPhone with PHP and pushme.to


 / Published in: PHP
 

URL: http://www.barattalo.it/2010/08/09/send-push-notification-to-iphone-with-php-and-pushme-to/#

Push service is a technology that allows you to send alerts/notifications to a mobile device. Blackberry has its own push service, iPhone has its own, and also Android devices has their own push services (you can learn more on Wikipedia page).\r\nPush notifications are like “sms” but they are free if you have a flat service contract on your mobile.\r\nI want to send push to my iPhone, but I’m not able to develop an iPhone application that receive push alerts, and I don’t want to send only email alerts.\r\nOk, let’s recap: I have an iPhone and I need to send notifications to my mobile from my PHP scripts.\r\nSo I’ve looked deeply in the appStore and I’ve found pushme.to application. This application is made to talk with friends trought web sites and iPhones.\r\nPushme.to is good because after you’ve registered you can go on their widget page and create a widget for your account to put on your web site. Well, in this post, I will not use this widget for my web site (I don’t want users to write me), but I will use their widget with a mini web bot to send alerts directly to my device through a PHP function.\r\nIt happens this way: the cron job calls my php script, my script uses a small bot to call pushme.to widget, pushmeTo sends alerts to my iPhone...

  1. function pushMeTo($widgeturl,$text,$signature) {
  2. $agent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12";
  3. if (!function_exists("curl_init")) die("pushMeTo needs CURL module, please install CURL on your php.");
  4. $ch = curl_init();
  5. curl_setopt($ch, CURLOPT_URL, $widgeturl);
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  7. curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  8. $page = curl_exec($ch);
  9. preg_match("/form action=\"(.*?)\"/", $page, $form_action);
  10. preg_match("/textarea name=\"(.*?)\"/", $page, $message_field);
  11. preg_match("/input type=\"text\" name=\"(.*?)\"/", $page, $signature_field);
  12. $ch = curl_init();
  13. $strpost = $message_field[1].'=' . urlencode($text) . '&'.$signature_field[1].'=' . urlencode($signature);
  14. curl_setopt($ch, CURLOPT_POSTFIELDS, $strpost );
  15. curl_setopt($ch, CURLOPT_URL, $form_action[1]);
  16. curl_setopt($ch, CURLOPT_POST, 1);
  17. curl_setopt($ch, CURLOPT_HEADER, 0);
  18. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  19. curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  20. $page = curl_exec($ch);
  21. }

Report this snippet  

You need to login to post a comment.