Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <html>
- <head>
- <style>
- .error {
- color:red;
- }
- .button {
- background-color: #4CAF50;
- border: none;
- color: white;
- padding: 10px 25px;
- text-align: center;
- text-decoration: none;
- display: inline-block;
- font-size: 16px;
- margin: 4px 2px;
- cursor: pointer;
- }
- .div1 {
- background-color: #f2f2f2;
- margin-top: -19px;
- margin-bottom: -25px;
- margin-left: -19px;
- }
- .copy {
- border-radius: 4px;
- padding: 6px 20px;
- border-style: ridge;
- }
- .copy1{
- border-radius: 4px;
- padding: 6px 28px;
- border-style: ridge;
- }
- .copy2 {
- border-radius: 4px;
- padding: 4px 2px;
- }
- </style>
- </head>
- <body>
- <?php
- // define variables and set to empty values
- include_once 'connect.php';
- $nameErr = $emailErr = $usernameErr = $passwordErr = $DateOfBirthErr =
- $departmentErr = $ageErr = "";
- $name = $email = $username = $password = $DateOfBirth = $department =
- $age = "";
- if (isset($_POST['submit'])) {
- if (empty($_POST["name"])) {
- $nameErr = "Name is required";
- } else {
- $name = test_input($_POST["name"]);
- // check if name only contains letters and whitespace
- if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
- $nameErr = "Only letters and white space allowed";
- }
- }
- if (empty($_POST["email"])) {
- $emailErr = "Email is required";
- } else {
- $email = test_input($_POST["email"]);
- // check if e-mail address is well-formed
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $emailErr = "Invalid email format";
- }
- }
- if (empty($_POST["username"])) {
- $usernameErr = "Username is required";
- } else {
- $username = test_input($_POST["username"]);
- // check if name only contains letters and whitespace
- if (!preg_match("/^[a-zA-Z ]*$/",$username)) {
- $usernameErr = "Only letters and white space allowed";
- }
- }
- if (empty($_POST["password"])) {
- $passwordErr = "Password is required";
- } else {
- $password = test_input($_POST["password"]);
- $hashed_password = password_hash($password, PASSWORD_DEFAULT);
- // check weather password is alphanumeric
- if(!preg_match('/^(?=.*d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{6,}$/',
- $password))
- {
- $passwordErr = "Password must be alphanumeric and atleast 6 characters
- long!";
- }
- }
- if (empty($_POST["Date_of_birth"])) {
- $DateOfBirthErr = "Date Of Birth is required";
- } else {
- $DateOfBirth = test_input($_POST["Date_of_birth"]);
- }
- if (empty($_POST["department"])) {
- $departmentErr = "Department is required";
- } else {
- $department = test_input($_POST["department"]);
- }
- if (empty($_POST["age"])) {
- $ageErr = "Age is required";
- } else {
- $age = test_input($_POST["age"]);
- }
- if($nameErr == "" && $emailErr == "" && $usernameErr == "" &&
- $passwordErr ==
- "")
- {
- $check="SELECT * FROM users WHERE username = '$_POST[username]'";
- $rs = mysqli_query($mysqli,$check);
- $da = mysqli_fetch_array($rs, MYSQLI_NUM);
- if($da[0] > 0) {
- echo "Username Already in Exists<br/>";
- }
- else
- {
- $sql = "INSERT INTO users(`id`,`username`, `password`, `email` , `name` ,
- `Date_of_birth` , `department` ,`age`)
- VALUES ('','".$username."', '".$hashed_password."', '".$email."' ,
- '".$name."' , '".$DateOfBirth."' , '".$department."' , '".$age."')";
- if (mysqli_query($mysqli, $sql)) {
- echo "Registered successfully";
- } else {
- echo "Error: " . $sql . "<br>" . mysqli_error($mysqli);
- }
- mysqli_close($mysqli);
- }
- }
- }
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- ?>
- <div style="padding-left: 250px" class="div1">
- <h2 style="color:#009999">Registration Form :</h2>
- <p><span class="error">All fields are required </span></p>
- <form method="post" action="">
- <span style="color:#0099ff">Name: </span>
- <input type="text" name="name" class= "copy" style="margin-left: 52px"
- value ="<?php
- if (isset($name))
- echo $name;
- ?>">
- <span class="error"> <?php echo $nameErr;?></span>
- <br><br>
- <span style="color:#0099ff"> E-mail: </span>
- <input type="text" name="email" class= "copy" style="margin-left:
- 48px" value
- ="<?php
- if (isset($email))
- echo $email;
- ?>">
- <span class="error"><?php echo $emailErr;?></span>
- <br><br>
- <span style="color:#0099ff"> Username: </span>
- <input type="text" name="username" class= "copy" style="margin-
- left:26px"
- value ="<?php
- if (isset($username))
- echo $username;
- ?>">
- <span class="error"> <?php echo $usernameErr;?></span>
- <br><br>
- <span style="color:#0099ff"> Password: </span>
- <input type="password" name="password" class= "copy" style="margin-
- left:30px">
- <span class="error"> <?php echo $passwordErr;?></span>
- <br><br>
- <span style="color:#0099ff"> Date Of Birth : </span>
- <input type="date" class= "copy1" name="Date_of_birth" value ="<?php
- if (isset($DateOfBirth))
- echo $DateOfBirth;
- ?>">
- <span class="error"> <?php echo $DateOfBirthErr;?></span>
- <br><br>
- <span style="color:#0099ff"> Age : </span>
- <input type="number" name="age" class= "copy" style="margin-left:62px"
- value
- ="<?php
- if (isset($age))
- echo $age;
- ?>">
- <span class="error"> <?php echo $ageErr;?></span>
- <br><br>
- <span style="color:#0099ff"> Department : </span>
- <select name="department" class= "copy2" style="margin-left:14px" value
- ="<?
- php
- if (isset($department))
- echo $department;
- ?>">
- <option value="EE">Electrical & Electronics</option>
- <option value="EC">Electronics & Communication</option>
- <option value="ME">Mechanical</option>
- <option value="CS">Computer Science</option>
- <option value="CV">Civil</option>
- <option value="IS">Information Science</option>
- </select>
- <span class="error"> <?php echo $departmentErr;?></span>
- <br><br>
- <input type="submit" class="button" name="submit" value="Register">
- <p style="color:black">Already Registered? <a
- href="login.php">Login</a>.
- </p>
- </form>
- </div>
- </body>
- </html>
- <?php
- $error="";
- include_once 'connect.php';
- if(isset($_SESSION['login_user']))
- {
- header('location:welcome.php');
- }
- session_start();
- if($_SERVER["REQUEST_METHOD"] == "POST") {
- // username and password sent from form
- $myusername = mysqli_real_escape_string($mysqli,$_POST['username']);
- $mypassword = mysqli_real_escape_string($mysqli,$_POST['password']);
- $sql = "SELECT * FROM users WHERE username = '$myusername' ";
- $result = mysqli_query($mysqli,$sql);
- $row = mysqli_fetch_array($result);
- $hashed_password=$row['password'];
- if(password_verify($mypassword, $hashed_password)) {
- $_SESSION['login_user'] = $myusername;
- header("location: welcome.php");
- exit();
- }
- else
- {
- $error = " Invalid Username or Password ";
- }
- }
- ?>
- <html>
- <head>
- <title>Login Page</title>
- <style type = "text/css">
- body {
- font-family:Arial, Helvetica, sans-serif;
- font-size:14px;
- }
- label {
- font-weight:bold;
- width:100px;
- font-size:14px;
- }
- .box {
- border:#666666 solid 1px;
- }
- .button {
- background-color: #4CAF50;
- border: none;
- color: white;
- padding: 10px 20px;
- text-align: center;
- text-decoration: none;
- display: inline-block;
- font-size: 12px;
- margin: 4px 2px;
- cursor: pointer;
- }
- </style>
- </head>
- <body bgcolor = "#FFFFFF">
- <div align = "center">
- <div style = "margin:30px">
- <form action = "" method = "post">
- <label>Username : </label><input type = "text" name =
- "username" class = "box"/><br /><br />
- <label>Password : </label><input type = "password" name =
- "password" class = "box" /><br/><br />
- <input class="button" type = "submit" value = " login "/><br
- />
- </form>
- <div style = "font-size:11px; color:#cc0000; margin-top:10px"><?
- php echo $error; ?></div>
- </div>
- </div>
- </body>
- </html>
- <?php
- include('session.php');
- if(!isset($_SESSION['login_user'])){
- header('location:login.php');
- }
- ?>
- <html>
- <head>
- <title>Welcome </title>
- </head>
- <body>
- <h1>Welcome <?php echo $login_session; ?></h1>
- <h2><a href = "logout.php">logOut</a></h2>
- </body>
- </html>
- <?php
- include_once 'connect.php';
- session_start();
- $user_check = $_SESSION['login_user'];
- $ses_sql = mysqli_query($mysqli,"select username from users where username
- =
- '$user_check' ");
- $row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
- $login_session = $row['username'];
- if(!isset($_SESSION['login_user'])){
- header("location:login.php");
- }
- ?>
- <?php
- session_start();
- if(session_destroy()) {
- header("Location: login.php");
- }
- ?>
- <?php
- $databaseHost = 'localhost';
- $databaseName = 'amith';
- $databaseUsername = 'root';
- $databasePassword = '';
- $mysqli = mysqli_connect($databaseHost, $databaseUsername,
- $databasePassword, $databaseName);
- ?>
Add Comment
Please, Sign In to add comment