Lesson 16:Lesson 15 Recap-USSD menu explanation and implementation

Lesson 15 Recap

In lesson 15, we wrote a some code. What you noticed is that, when the user dials the USSD code, no text is sent USSD gateway, and, therefore, to the production server. You realize that we are using ‘level’ to track the number of replies the user has made. So, in the beginning, the $level=0 because the user hasn’t replied. 

So, while the level of is zero, 


if ($level==0){

 The displaymenu() method displays what the user sees as initial menu as shown below


function displaymenu(){
$ussd_text="CON Welcome to UCURESULTS. Please reply with; <br/>1.        Register<br/>2. Login<br/>";

And is printed as shown below

function ussd_proceed ($ussd_text){
echo $ussd_text;

 If the the level is greater than 0, the you need to determine 2 things;

  • What the user replied with and 
  • Count, which is the number of times the user has replied 


$ussdString=  str_replace("#", "*", $ussdString);
$ussdString_explode = explode("*", $ussdString);
$level = count($ussdString_explode);


str_replace replaces all #’s with *’s, which then is exploded with * as the separator to give an array. Array index starts at 0, so we pass value at 0, to check what value the user selected, ($ussdString_explode[0]). 

The user got to select 1 or 2 for 1. Register and 2. Login respectively.  

Step 2 requires the user to input registration number, this will be stored in index 1 of the $details. For registration, the details will be found in the following indexes as follows




and for Login, the values are found in the indexes as shown below,



In this lesson, we have discussed the code we wrote in Lesson 15 . What we noted is that, we track what the user uses to reply, and the number of replies the user has made. We can as well collect data from users as shown in the code snippets. 

In the next lesson, we are going to look at how you let your application know when to display a user input box and when to end the USSD session:- remember that USSD is session oriented.   

Feel free to leave a comment or a question…..

    • Derdus Kenga
    • Derdus Kenga

Add a Comment

Your email address will not be published. Required fields are marked *