Last active
November 25, 2019 18:14
-
-
Save pipethedev/46553c77b84568b720b1bb889f8653d3 to your computer and use it in GitHub Desktop.
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 | |
$message = ""; | |
//initializing connection variables | |
$servername = "localhost"; | |
$username = "username"; | |
$password = "password"; | |
$dbname = "myDB"; | |
// Create connection | |
$conn = new mysqli($servername, $username, $password, $dbname); | |
// Check connection | |
if ($conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error); | |
} | |
//user's information | |
$firstname = filter_var(mysqli_real_escape_string($conn, $_POST['firstname'])); | |
$lastname = filter_var(mysqli_real_escape_string($conn, $_POST['lastname'])); | |
$email = filter_var(mysqli_real_escape_string($conn, $_POST['email'])); | |
//code formation | |
$generator = "1234567890"; | |
//shuffling generator and specifying 6-digit code | |
$code = substr(str_shuffle($generator), 0, 6); | |
$sql = "INSERT INTO users (firstname, lastname, email, code) VALUES ('$firstname', '$lastname', '$email', '$code')"; | |
if ($conn->query($sql) === TRUE) { | |
$message = "Check your inbox for your code !!!"; | |
//storing code for only 10 minutes (Setting cookie) | |
setcookie("code", $code, time() +(10*60*60)); | |
//redirecting user to validation page | |
header('location: validate.php'); | |
} else { | |
$message = "Error: " . $sql . "<br>" . $conn->error; | |
} | |
$conn->close(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment