To add country restriction to your apps, you will be making use of the Mxit Specific Headers which allows you access to users’ location. If you don’t want users from a certain location to access your app, you can set up specifications that denies them access to your app, and return a message explaining why they can’t access the app.
Step 1:
Since the Profile header only returns what the user has selected during registration, you will need to obtain the users’ location using the X-MXit-Location and not the X-MXit-Profile.
$temp = $headers["X-MXit-Location"];
Step 2:
The above code snippet will return the a string similar to the following: ZA,South Africa,11,Western Cape,23,Kraaifontein,88,13072382,8fbe253.
For this example, we have chosen to use the country ISO 3166-1 alpha-2 code, however you can use the Country Name as well.
To extract the two digit country ISO, is as simply as:
$matches = array();
if (preg_match('/^([A-Za-z]+),.+$/',$temp,$matches))
{
$matches[1] ;
}
else
{
$matches[1] = "N/D";
}
The above is needed just in case the location cannot be determined and the header returns blank.
Step 3:
Now that you have the location saved in your matches array you can use it to determine if the user is from the desired location:
if ($matches[1] == "ZA")
{
echo '<a href="18plus.php">Proceed</a>';
}
else
{
echo "Sorry your location $matches[1] does not allow you to view this content.";
}
Please note that some BlackBerry devices prevents you from detecting the correct location as they are set up as being in the UK due to internet routing. Unfortunately we don’t have a workaround for this, but if you have a suggestion on a workaround, you are welcome to send it to us via our Mxit Developer Support Center.