Last active
August 20, 2019 07:26
-
-
Save tofbabs/e7b6277792d962e9fcb6c6880bed4809 to your computer and use it in GitHub Desktop.
MSISDN Authentication sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
** VALIDATE SUBSCRIPTION | |
** @desc Redirect to Subscription Page if Number not detected or Subscription has expired | |
** Ref: include/auth.php | |
*/ | |
function validate_subscription(){ | |
$expiry_date = isset($_SESSION['expiryDate']) ? $_SESSION['expiryDate'] : null; | |
// Logout | |
if (isset($_GET['do']) && $_GET['do'] == 'logout') { | |
# Set Expiry date to old | |
$expiry_date = date('2016-01-01'); | |
} | |
if ( isset($_GET['m']) && isset($_GET['d']) ) { | |
$_SESSION['user_data'] = null; | |
// Decode MSISDN and accompanying data | |
foreach($_GET as $loc => $item) $_GET[$loc] = str_rot13($item); | |
$_SESSION['_msisdn'] = $_GET['m']; | |
$_SESSION['expiryDate'] = $_GET['d']; | |
$expiry_date = $_GET['d']; | |
// Empty GET array | |
$_GET = array(); | |
} | |
if ( !isset($_SESSION['_msisdn']) || ( isset($_SESSION['_msisdn']) && isExpired($expiry_date) ) ) | |
header('Location: http://5.101.138.139/subscription/s/[SERVICE_ID]'); | |
// Go to Site | |
} | |
/* | |
* Check if subscription is expired for user or user is new | |
* @return BOOL | |
*/ | |
function isExpired($expiry_date){ | |
$cur_date = date('Y-m-d', $_SERVER['REQUEST_TIME']); | |
if ( $expiry_date < $cur_date || is_null($expiry_date) ) { | |
session_destroy(); | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment