SHARE
TWEET

Untitled

a guest Sep 19th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. ini_set('display_errors', 1);
  3. session_start();
  4. ?>
  5.  
  6. <?php
  7.     if ($_POST) {
  8.     //Name validation
  9.     $sName = $_POST['txtName'];
  10.     if (empty($_POST['txtName'])) {
  11.         sendErrorMessage('Full name is missing');
  12.     }
  13.  
  14.     if (strlen($_POST['txtName']) < 2 || strlen($_POST['txtName']) > 50) {
  15.         sendErrorMessage('Full name should have Min 2 and Max 50 characters');
  16.     }
  17.     //First name, surname
  18.     if (!preg_match("/^[a-zA-Z][a-z]+\s{1}[a-zA-Z][a-z]*$/", $sName)) {
  19.         sendErrorMessage('Type name & surname 1 space appart');
  20.     }
  21.  
  22.     //Email validation
  23.     $sEmail = $_POST['txtEmail'];
  24.     if (empty($_POST['txtEmail'])) {
  25.         sendErrorMessage('Email is missing');
  26.         exit();
  27.     }
  28.     if (!filter_var($_POST['txtEmail'], FILTER_VALIDATE_EMAIL)) {
  29.         sendErrorMessage('Email is invalid');
  30.         exit();
  31.     }
  32.  
  33.     //Password validation
  34.     $sPassword = $_POST['txtPassword'];
  35.     if (empty($_POST['txtPassword'])) {
  36.         sendErrorMessage('Password is missing');
  37.         exit();
  38.     }
  39.     if (strlen($_POST['txtPassword']) < 8) {
  40.         sendErrorMessage('Password is too short');
  41.     }
  42.     if (strlen($_POST['txtPassword']) > 50) {
  43.         sendErrorMessage('Password is too long');
  44.     }
  45.  
  46.     $jAgent = new stdClass();
  47.     $jAgent->name = $sName;
  48.     $jAgent->email = $sEmail;
  49.     $jAgent->password = $sPassword;
  50.  
  51.     $jAgent->properties = new stdClass();
  52.     $sAgentUniqueId = uniqid();
  53.  
  54.     $sjData = file_get_contents('data/data.json');
  55.     $jData = json_decode($sjData);
  56.  
  57.     $jData->agents->$sAgentUniqueId = $jAgent;
  58.     $sjData = json_encode($jData, JSON_PRETTY_PRINT);
  59.     file_put_contents('data/data.json', $sjData);
  60.     $_SESSION['id'] =  $jAgent;
  61.     header('Location: agent-profile.php');
  62.     //header("location: agent-profile.php?name=$sName");
  63. }
  64.     function sendErrorMessage($sErrorMessage)
  65.     {
  66.         $sEmail = $_POST['txtEmail'];
  67.         $sPassword = $_POST['txtPassword'];
  68.         echo '<form method="POST">
  69.         <input name="txtName" type="text" placeholder="Name" value="' . $sName . '" >
  70.         <input name="txtEmail" type="text" placeholder="Email" value="' . $sEmail . '" >
  71.         <input name="txtPassword" type="password" placeholder="Password" value="' . $sPassword . '">
  72.        
  73.         <button>SIGNUP AS AGENT</button>
  74.     </form>';
  75.         echo "<p>$sErrorMessage</p>";
  76.         exit;
  77.     }
  78.     echo '{"status":"0","message":"error in " , "Line":' . __LINE__ }';
  79.     ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top