Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $username = "";
- $email = "";
- $errors= array();
- $con=mysqli_connect('localhost','root','','user');
- if(isset($_POST['register'])) {
- $username = mysqli_real_escape_string($con, $_POST['username']);
- $email = mysqli_real_escape_string($con, $_POST['email']);
- $password_1 = mysqli_real_escape_string($con, $_POST['password_1']);
- $password_2 = mysqli_real_escape_string($con, $_POST['password_2']);
- if (empty($username)) {
- array_push($errors,"Username is required");
- }
- if (empty($email)) {
- array_push($errors, "User email is required");
- }
- if (empty($password_1)) {
- array_push($errors, "User Password is required");
- }
- if ($password_1 != $password_2) {
- array_push($errors, "Password did not match");
- }
- if (count($errors) == 0) {
- $password = md5($password_1);
- $sql="INSERT INTO user (username, email, password) VALUES ('$username','$email','$password')";
- mysqli_query($con, $sql);
- $_SESSION['username'] = $username;
- $_SESSION['success'] = "You are now Registered.";
- header('location: confo.php');
- }
- if (isset($con, $_POST['login'])) {
- $username = mysqli_real_escape_string($con, $_POST['username']);
- $password = mysqli_real_escape_string($con, $_POST['password']);
- if (empty($username)) {
- array_push($errors,"Username is required");
- }
- if (empty($password)) {
- array_push($errors, "Valid password is required");
- }
- if (count($errors) == 0) {
- $password = md5($password);
- $query = "SELECT * FROM regi WHERE username='$username' AND password='$password' ";
- $result = mysqli_query($con, $query);
- if (mysqli_num_rows($result) == 1) {
- $_SESSION['username'] = $username;
- $_SESSION['success'] = "You are now Registered.";
- header('location: confo.php');
- }else{
- array_push($errors, "The username/password did not match");
- }
- }
- }
- if (isset($_GET['logout'])) {
- session_destroy();
- unset($con, $_SESSION['username']);
- header('location: login.php');
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement