Skip to content

Instantly share code, notes, and snippets.

@toksdotdev
Forked from drizzentic/index.php
Created May 12, 2017 08:35
Show Gist options
  • Save toksdotdev/37f96e54eb491a8dc69e254c8445bb24 to your computer and use it in GitHub Desktop.
Save toksdotdev/37f96e54eb491a8dc69e254c8445bb24 to your computer and use it in GitHub Desktop.
Sample USSD Application
<!-- MIT License
Copyright (c) 2016 Derrick Rono
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. -->
<?php
#We obtain the data which is contained in the post url on our server.
$text=$_GET['USSD_STRING'];
$phonenumber=$_GET['MSISDN'];
$serviceCode=$_GET['serviceCode'];
$level = explode("*", $text);
if (isset($text)) {
if ( $text == "" ) {
$response="CON Welcome to the registration portal.\nPlease enter you full name";
}
if(isset($level[0]) && $level[0]!="" && !isset($level[1])){
$response="CON Hi ".$level[0].", enter your ward name";
}
else if(isset($level[1]) && $level[1]!="" && !isset($level[2])){
$response="CON Please enter you national ID number\n";
}
else if(isset($level[2]) && $level[2]!="" && !isset($level[3])){
//Save data to database
$data=array(
'phonenumber'=>$phonenumber,
'fullname' =>$level[0],
'electoral_ward' => $level[1],
'national_id'=>$level[2]
);
$response="END Thank you ".$level[0]." for registering.\nWe will keep you updated";
}
header('Content-type: text/plain');
echo $response;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment