From: indresh Date: Thu, 26 Apr 2018 15:40:57 +0530 Subject: error handling --- error handling --- --- 'a/otp_form.php' +++ b/otp_form.php @@ -1,39 +1,38 @@ - - - - - - - + + + + + + + + -
" . $message . "
"; + unset($_SESSION[$msg]); } ?>
@@ -66,12 +65,12 @@ $verification = 'Y';

Please Verify OTP for Login

- -
- -
- - + +
+ +
+ +
@@ -79,87 +78,70 @@ $verification = 'Y'; - - $clientid, - 'uid' => $uid, - 'dob' => $dob, - 'name' => $name, - 'gender' => $gender, - 'otp' => $otp, - 'mobile' => $mobile, - 'verification' => $verification, - 'ts' => $ts, - 'hmac' => $hmac -); + $secret = $config['client_secret_download']; + $ts = time(); + $otp = $_POST['otp']; + $hmac = hash('SHA256', $secret . $clientid . $mobile . $otp . $ts); + $url = $config['demoauthverify_url']; + $post = array( + 'clientid' => $clientid, + 'uid' => $uid, + 'dob' => $dob, + 'name' => $name, + 'gender' => $gender, + 'otp' => $otp, + 'mobile' => $mobile, + 'verification' => $verification, + 'ts' => $ts, + 'hmac' => $hmac + ); $vh = curl_init($url); -curl_setopt($vh, CURLOPT_CUSTOMREQUEST, "POST"); -curl_setopt($vh, CURLOPT_POST, true); -curl_setopt($vh, CURLOPT_TIMEOUT, 30); -curl_setopt($vh, CURLOPT_HEADER, 1); -curl_setopt($vh, CURLOPT_POSTFIELDS, $post); -curl_setopt($vh, CURLOPT_SSL_VERIFYPEER, 0); -curl_setopt($vh, CURLOPT_SSL_VERIFYHOST, 0); -curl_setopt($vh, CURLOPT_RETURNTRANSFER, true); -$result = curl_exec($vh); -$curl_info = curl_getinfo($vh); -if (curl_errno($vh)) { - $error_status = curl_error($vh); - curl_close($vh); -} else { - curl_close($vh); -} -print_r($result); -$header_size = $curl_info['header_size']; -$header = substr($result, 0, $header_size); -$body = substr($result, $header_size); -$header = explode("\n", $header); - - -$statuscode = (int)substr($header[2], 9, 3); -$rest = json_decode($body); - -if($statuscode=='200') -{ - header("Location: signup.php?message=Your Account has been created. Please login through this link "); - exit; -} -else -{ -if(isset($rest->error) || !$result){ - - header("Location: otp_form.php?message=".$rest->error_description); - exit; -} -} + curl_setopt($vh, CURLOPT_CUSTOMREQUEST, "POST"); + curl_setopt($vh, CURLOPT_POST, true); + curl_setopt($vh, CURLOPT_TIMEOUT, 30); + curl_setopt($vh, CURLOPT_HEADER, 1); + curl_setopt($vh, CURLOPT_POSTFIELDS, $post); + curl_setopt($vh, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($vh, CURLOPT_SSL_VERIFYHOST, 0); + curl_setopt($vh, CURLOPT_RETURNTRANSFER, true); + $result = curl_exec($vh); + $curl_info = curl_getinfo($vh); + if (curl_errno($vh)) { + $error_status = curl_error($vh); + curl_close($vh); + } else { + curl_close($vh); + } + print_r($result); + $header_size = $curl_info['header_size']; + $header = substr($result, 0, $header_size); + $body = substr($result, $header_size); + $header = explode("\n", $header); + $statuscode = (int) substr($header[2], 9, 3); + $rest = json_decode($body); + if ($statuscode == '200') { + $_SESSION['message'] = "Your Account has been created. Please login through this link "; + header("Location: signup.php"); + exit; + } else { + if (isset($rest->error) || !$result) { + $_SESSION['message'] = $rest->error_description; + header("Location: otp_form.php"); + exit; + } + } } ?> - - - - - - + + + + + --- 'a/signup.php' +++ b/signup.php @@ -3,12 +3,12 @@
" . $message . "
"; + echo "
" . $message . "
"; } + session_destroy(); ?> @@ -51,7 +51,7 @@
@@ -89,13 +89,3 @@ endDate: "today" }); - --- 'a/signupcurl.php' +++ b/signupcurl.php @@ -1,9 +1,5 @@ this link "); + $_SESSION['message'] = "Your Account has been created. Please login through this link "; + header("Location: signup.php"); exit; } - -//$rst = json_decode($result); if(isset($rst->error) || !$result){ - header("Location: signup.php?message=".$rst->error_description); + $_SESSION['message'] = $rst->error_description; + header("Location: signup.php"); exit; } if(!empty($rst->mobile)) { $path = $config['baseUrl']; - header('Location: '.$path.'otp_form.php?uid='.$uid.'&name='.$name.'&dob='.$dob.'&gen='.$gender.'&mob='.$mobile); + $_SESSION['name'] = $name; + $_SESSION['uid'] = $uid; + $_SESSION['dob'] = $dob; + $_SESSION['gen'] = $gender; + $_SESSION['mob'] = $mobile; + $_SESSION['verification'] = $verification; + header('Location: '.$path.'otp_form.php'); } ?> \ No newline at end of file