Skip to content

Instantly share code, notes, and snippets.

@drizzentic
Created July 19, 2016 14:20
Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 46 You must be signed in to fork a gist
  • Save drizzentic/18522c06e4529c58bc82fefe429e319b to your computer and use it in GitHub Desktop.
Save drizzentic/18522c06e4529c58bc82fefe429e319b 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;
}
?>
@FelixWatilah
Copy link

Thanks buddy for your assistance. I was figuring out how to start learning USSD codes.

@Ntungwe
Copy link

Ntungwe commented Jul 8, 2017

am new in this and i want to test the code
where do i see "open postman client"

@DavidInnocent
Copy link

Come on man...this is a sham!
That wont give you such an interface on your phone that is a blueprint.

@lekhrajpwt
Copy link

How can i go back to the previous level?
e.g: If an user is on level 3 and he wants to go to level 2 without quitting the current session.
How can be this done?

@TimzOwen
Copy link

how can i get this code and run it?

@markphi2013
Copy link

To help you guys run the code please try to use Africa's talking API https://africastalking.com/
It helped me

@TG-Codes
Copy link

Thanks man

@Emma7li
Copy link

Emma7li commented Aug 23, 2019

I appreciate this. It's simple example to start with USSD.

@drizzentic
Copy link
Author

drizzentic commented Aug 23, 2019

Come on man...this is a sham!
That wont give you such an interface on your phone that is a blueprint.
@DavidInnocent You should have read the title of the gist.

@chandiprasad1
Copy link

chandiprasad1 commented Sep 21, 2019

Code is fine. will it work on gsm phones? Could you please guide me step by step to build application which we can run on old phones

@Keneemma7
Copy link

This is a good start thanks

@nivedkrishnan
Copy link

how can add a back button option in this ussd

@Dalo-Chinkhwangwa-Prof
Copy link

Thank you for this!

@temamawelu
Copy link

is it working on kannel open source gatway

@Anneline25
Copy link

Thank you so much

@Freza-Mwenda
Copy link

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment