Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors', 1);
- session_start();
- ?>
- <?php
- if ($_POST) {
- //Name validation
- $sName = $_POST['txtName'];
- if (empty($_POST['txtName'])) {
- sendErrorMessage('Full name is missing');
- }
- if (strlen($_POST['txtName']) < 2 || strlen($_POST['txtName']) > 50) {
- sendErrorMessage('Full name should have Min 2 and Max 50 characters');
- }
- //First name, surname
- if (!preg_match("/^[a-zA-Z][a-z]+\s{1}[a-zA-Z][a-z]*$/", $sName)) {
- sendErrorMessage('Type name & surname 1 space appart');
- }
- //Email validation
- $sEmail = $_POST['txtEmail'];
- if (empty($_POST['txtEmail'])) {
- sendErrorMessage('Email is missing');
- exit();
- }
- if (!filter_var($_POST['txtEmail'], FILTER_VALIDATE_EMAIL)) {
- sendErrorMessage('Email is invalid');
- exit();
- }
- //Password validation
- $sPassword = $_POST['txtPassword'];
- if (empty($_POST['txtPassword'])) {
- sendErrorMessage('Password is missing');
- exit();
- }
- if (strlen($_POST['txtPassword']) < 8) {
- sendErrorMessage('Password is too short');
- }
- if (strlen($_POST['txtPassword']) > 50) {
- sendErrorMessage('Password is too long');
- }
- $jAgent = new stdClass();
- $jAgent->name = $sName;
- $jAgent->email = $sEmail;
- $jAgent->password = $sPassword;
- $jAgent->properties = new stdClass();
- $sAgentUniqueId = uniqid();
- $sjData = file_get_contents('data/data.json');
- $jData = json_decode($sjData);
- $jData->agents->$sAgentUniqueId = $jAgent;
- $sjData = json_encode($jData, JSON_PRETTY_PRINT);
- file_put_contents('data/data.json', $sjData);
- $_SESSION['id'] = $jAgent;
- header('Location: agent-profile.php');
- //header("location: agent-profile.php?name=$sName");
- }
- function sendErrorMessage($sErrorMessage)
- {
- $sEmail = $_POST['txtEmail'];
- $sPassword = $_POST['txtPassword'];
- echo '<form method="POST">
- <input name="txtName" type="text" placeholder="Name" value="' . $sName . '" >
- <input name="txtEmail" type="text" placeholder="Email" value="' . $sEmail . '" >
- <input name="txtPassword" type="password" placeholder="Password" value="' . $sPassword . '">
- <button>SIGNUP AS AGENT</button>
- </form>';
- echo "<p>$sErrorMessage</p>";
- exit;
- }
- echo '{"status":"0","message":"error in " , "Line":' . __LINE__ }';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement