HollaTags API
  • Introduction
  • 📳SMS
    • Send
    • Receive
    • Status
    • Credit
    • Lookup
    • Send SMS Sample Code
    • Receive SMS Sample Code
    • API Response
    • Callback
    • OTP
    • SMS DLR Error Codes
  • 📳USSD
    • USSD Inbound
    • USSD Outbound
    • USSD Sample Code
    • USSD Error Codes
  • 📳WhatsApp
    • WhatsApp Chat
    • WhatsApp Push
    • WhatsApp Sample Code
  • 📳SMPP
    • SMPP Specification
    • SMPP Servers
    • SMPP Authentication
    • SMPP Configuration
    • SMPP Message PDU
    • SMPP Client Configuration
    • SMPP Response Codes
    • SMPP DLR Codes
  • 💳Airtime
    • Airtime (VTU)
  • ❓FAQ
    • USSD - Dedicated
    • USSD - Shared
Powered by GitBook
On this page

Was this helpful?

  1. USSD

USSD Sample Code

Sample USSD Menu Code

Below is a sample 2-level USSD menu in PHP. This can be extended in the same format to an unlimited menu level within the session timeout period permitted on the USSDC.

<?php

/*
* Read HTTP GET values
*/

$session_msisdn = $_GET['session_msisdn'];
$session_operation = $_GET['session_operation']; /* begin, continue, end */
$session_type = $_GET['session_type']; /* 1, 2, 3, 4 */
$session_msg = trim($_GET['session_msg']);
$session_id = $_GET['session_id'];
$session_from = $_GET['session_from']; /* shortcode */

/*
* Depending on the USSD operation category, send a corresponding 
* response message back to the subscriber.
*/

if (strcmp($session_operation, "begin") == 0) {
    $output['session_operation'] = "continue";
    $output['session_type'] = 1;
    $output['session_id'] = $session_id;
    $output['session_msg'] = "Welcome to eBanking.\nPlease select your payment channel.\n1) Card\n2) Bank Account\n3) Wallet";
} elseif (strcmp($session_operation, "continue") == 0) {
    $output['session_operation'] = "end";
    $output['session_type'] = 4;
    $output['session_id'] = $session_id;

    /*
    * Below is the business logic based on the response of the user.
    * You can pass this to your database, internal system etc.
    */

    switch ($session_msg) {
        case 1:
            $channel = "Card";

            break;
        case 2:
            $channel = "Bank Account";

            break;
        case 3:
            $channel = "Wallet";

            break;
        default:
            $channel = "NONE";
    }

    $output['session_msg'] = "You selected -$channel-. Have a great day.";
} else {
    $output['session_operation'] = "end";
    $output['session_type'] = 4;
    $output['session_id'] = $session_id;
    $output['session_msg'] = "Thank you.";
}

echo json_encode($output); /* this JSON output goes to the USSDC */

exit;

PreviousUSSD OutboundNextUSSD Error Codes

Last updated 5 years ago

Was this helpful?

📳