Revision: 25333
Updated Code
at March 27, 2010 18:02 by Meander365
Updated Code
// html + jquery
<script type="text/javascript" src="_assets/behaviour/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#notifo").submit(function(e) {
e.preventDefault();
$.getJSON("notifo-proxy.php?username=" + $("#username").attr("value"),
function (data) {
switch (parseInt(data.response_code)) {
case 2201:
//success
$('.result').html( "Success! " + data.response_message );
break;
case 2202:
//success - already registered
$('.result').html( "You're already subscribed! " + data.response_message );
break;
default:
//error - see the response codes of notifo's api
$('.result').html( "There was an error. " + data.response_message );
}
}
)
})
});
</script>
<div class="notfio">
<h1>Notifo Example</h1>
<form id="notifo" action="notifo-proxy.php" >
<input type="text" id="username" name="username" value="" />
<input type="submit" value="go" />
</form>
</div>
<div class="result">
<!-- server responses here -->
</div>
<?php
//-----------------------------------------------------------------------------------
//get username
$username = $_GET['username'];
//Create the connection handle
$curl_conn = curl_init();
//Set cURL options
curl_setopt($curl_conn, CURLOPT_URL, "https://api.notifo.com/v1/subscribe_user");
curl_setopt($curl_conn, CURLOPT_POST, true);
curl_setopt($curl_conn, CURLOPT_POSTFIELDS,"username=" . $username);
curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //Use basic authentication
curl_setopt($curl_conn, CURLOPT_USERPWD, "your-servicename:your-servicename-secret");
curl_setopt($curl_conn, CURLOPT_SSL_VERIFYPEER, false); //Do not check SSL certificate
curl_setopt($curl_conn, CURLOPT_RETURNTRANSFER, 1); //Return the result as string
// Result from querying URL. Will parse as xml
$output = curl_exec($curl_conn);
// close cURL resource.
curl_close($curl_conn);
echo $output;
//-----------------------------------------------------------------------------------
?>
Revision: 25332
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 27, 2010 18:00 by Meander365
Initial Code
<?php //----------------------------------------------------------------------------------- //get username $username = $_GET['username']; //Create the connection handle $curl_conn = curl_init(); //Set cURL options curl_setopt($curl_conn, CURLOPT_URL, "https://api.notifo.com/v1/subscribe_user"); curl_setopt($curl_conn, CURLOPT_POST, true); curl_setopt($curl_conn, CURLOPT_POSTFIELDS,"username=" . $username); curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //Use basic authentication curl_setopt($curl_conn, CURLOPT_USERPWD, "your-servicename:your-servicename-secret"); curl_setopt($curl_conn, CURLOPT_SSL_VERIFYPEER, false); //Do not check SSL certificate curl_setopt($curl_conn, CURLOPT_RETURNTRANSFER, 1); //Return the result as string // Result from querying URL. Will parse as xml $output = curl_exec($curl_conn); // close cURL resource. curl_close($curl_conn); echo $output; //----------------------------------------------------------------------------------- ?>
Initial URL
http://www.notifo.com/
Initial Description
Example of how to send a subscribe_user request using Notifo's api. Notifo lets you setup push notifications to mobiles - for any site. Put the PHP into a separate file named notifo-proxy.php
Initial Title
Notifo Subscribe Request Using PHP, CURL and Jquery
Initial Tags
curl, php, jquery
Initial Language
PHP