Notification push vers iphone ou ipad via php

php_push_iphone_02

22 juin Notification push vers iphone ou ipad via php

Voici un article expliquant comment envoyer une notification push sur ipad ou iphone à partir d’une script PHP

Il est possible de télécharger une application gratuite sur AppleStore : pushme.to

Cette application permet notamment d’envoyer un push vers un iphone depuis un widget.

Je ne mettrais pas un widget ce de type sur ce blog….. ;)

Donc pour utiliser cette application, vous devrez ouvrir gratuitement un compte (pseudo + mot de passe + email).

Ensuite, sur votre page pushme.to, vous aurez la possibilité de récupérer le code html pour insérer le widget permettant d’installer cette notification push vers votre ipad ou iphone.

Le code devra ressembler à ceci :

<pre><span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">http://pushme.to/q/widget/export/?hash=51ff0b6e3c1ce3a7a7e473198e1b6d9a</span> http://pushme.to/q/widget/export/?hash=51ff0b6e3c1ce3a7a7e473198e1b6d9a</span></pre>

Ensuite, en utilisant le script ci-dessous, vous pourrez envoyer vos noficiation push vers votre iphone

<code></code>
<pre><span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">function pushMeTo($widgeturl,$text,$signature) {</span> Fonction pushMeTo (widgeturl $, $ text, $ signature) {</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">$agent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12";</span> $ Agent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; fr; rv: 1.9.0.12) Gecko/2009070611 Firefox/3.0.12»;</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">if (!function_exists("curl_init")) die("pushMeTo needs CURL module, please install CURL on your php.");</span> si die ("pushMeTo besoins module CURL, s'il vous plaît installer sur votre CURL de PHP.") (function_exists ("curl_init")!);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">$ch = curl_init();</span> $ Ch = curl_init ();</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">curl_setopt($ch, CURLOPT_URL, $widgeturl);</span> curl_setopt ($ ch, CURLOPT_URL, widgeturl $);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);</span> curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">curl_setopt($ch, CURLOPT_USERAGENT, $agent);</span> curl_setopt ($ ch, CURLOPT_USERAGENT, $ agent);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">$page = curl_exec($ch);</span> $ Page = curl_exec ($ ch);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">preg_match("/form action=\"(.*?)\"/", $page, $form_action);</span> preg_match ("action / form = \ "(.*?) \" / ", $ page, $ form_action);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">preg_match("/textarea name=\"(.*?)\"/", $page, $message_field);</span> preg_match ("/ textarea name = \ "(.*?) \" / ", $ page, $ message_field);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">preg_match("/input type=\"text\" name=\"(.*?)\"/", $page, $signature_field);</span> preg_match ("type d'entrée / = \" text \ "name = \ "(.*?) \" / ", $ page, $ signature_field);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">$ch = curl_init();</span> $ Ch = curl_init ();</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">$strpost = $message_field[1].'=' .</span> $ $ = Strpost message_field [1 ].'='.</span> <span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">urlencode($text) .</span> urlencode ($ text).</span> <span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">'&'.$signature_field[1].'=' .</span> '&'.$ Signature_field [1 ].'='.</span> <span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">urlencode($signature);</span> urlencode ($ signature);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">curl_setopt($ch, CURLOPT_POSTFIELDS, $strpost );</span> curl_setopt ($ ch, CURLOPT_POSTFIELDS, strpost $);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">curl_setopt($ch, CURLOPT_URL, $form_action[1]);</span> curl_setopt ($ ch, CURLOPT_URL, form_action $ [1]);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">curl_setopt($ch, CURLOPT_POST, 1);</span> curl_setopt ($ ch, CURLOPT_POST, 1);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">curl_setopt($ch, CURLOPT_HEADER, 0);</span> curl_setopt ($ ch, CURLOPT_HEADER, 0);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);</span> curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">curl_setopt($ch, CURLOPT_USERAGENT, $agent);</span> curl_setopt ($ ch, CURLOPT_USERAGENT, $ agent);</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">$page = curl_exec($ch);</span> $ Page = curl_exec ($ ch);</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">}</span> }</span></pre>

 

En utilisant ceci par exemple

<pre><span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left"><?</span> <?</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">// ...</span> / / ...</span> <span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">send an alert if database is down...</span> envoyer une alerte si la base est en baisse ...</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">$url = "http://pushme.to/q/widget/export/?hash=51ff0b6e3c1ce3a7a7e473198e1b6d9a";</span> $ Url = "http://pushme.to/q/widget/export/?hash=51ff0b6e3c1ce3a7a7e473198e1b6d9a»;</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">if (!mysql_connect( "domain", "user", "password" )) {</span> if (! mysql_connect ("domaine", "utilisateur", "password")) {</span>
	<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">pushmeTo ($url,"Mysql server 'domain' is down!","Your Bot");</span> pushmeTo ($ url, "" domaine "serveur MySQL est en bas!", "Votre Bot»);</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">}</span> }</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span style="direction: ltr; text-align: left">?></span> ?></span>

 

 

Be Sociable, Share!
Tags:
, , , ,
No Comments

Post A Comment