USSD Code Development by Chris Aydat.

Chris Festus Otopa Ayeh-Datey
2 min readSep 24, 2023

https://github.com/chrisaydat/ussddevelopment.git

Unstructured Supplementary Service Data (USSD) is a protocol that allows basic feature phones to interact with backend systems. In this article, we will go through a USSD code sample developed by Aydat, Inc. to understand how such applications are built.

Overview

The USSD application developed by (chris) Aydat, Inc for Dyrect. provides the following capabilities:

- User registration

- Balance inquiry

- P2P money transfers

- Purchases

We will understand how the code implements these features.

Application Flow

The high-level flow is:

1. User dials USSD code on their phone

2. Main handler is invoked which displays menu

3. User input is processed to navigate menu options

4. Relevant actions like transactions, queries are performed

This is enabled by PHP code and USSD protocol features.

Main Handler

The `ussd.php` file handles the USSD session:

```php

//ussd.php

$text = $_GET[‘text’];

$data = explode(“*”, $text);

//determine menu level

$level = count($data);

//route user input

switch($data[1]){

case 1:

registration();

break;

case 2:

balance();

break;

//…other cases

}

```

It receives user input, parses it to identify menu level, and routes it accordingly.

Registration Flow

Registration prompts user for details one by one:

```php

//functions.php

function registration(){

if($level == 1){

askFirstName();

}

if($level == 2){

askLastName();

}

//…other fields

if($level == 9){

saveToDB();

confirmRegistration();

}

}

```

`ussd_proceed()` is used to prompt for next field.

## Session Control

```php

ussd_proceed() & ussd_stop() are used to manage session:

function ussd_proceed($text){

echo “CON $text”;

exit(0);

}

function ussd_stop($text){

echo “END $text”;

exit(0);

}

```

Database Integration

`connection.php` sets up database connectivity:

```php

//connection.php

$host = “localhost”;

$username = “ussd”;

$password = “123456”;

$db = new mysqli($host, $username, $password, “ussdApp”);

//execute queries

```

Used for registration, balance check etc.

Conclusion

The Next Version of this Article Will explore Database Connections and Final Deployment

--

--