Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $mysql_hostname = "localhost";
- $mysql_user = "root";
- $mysql_password = "";
- $mysql_database = "simple_login";
- $prefix = "";
- $bd = mysqli_connect($mysql_hostname, $mysql_user, $mysql_password, $mysql_database) or die("Could not connect database");
- ?>
- <?php
- //Start session
- session_start();
- //Include database connection details
- require_once('connection.php');
- //Array to store validation errors
- $errmsg_arr = array();
- //Validation error flag
- $errflag = false;
- //Function to sanitize values received from the form. Prevents SQL injection
- function clean($str) {
- $str = @trim($str);
- if(get_magic_quotes_gpc()) {
- $str = stripslashes($str);
- }
- return mysqli_real_escape_string($str);
- }
- //Sanitize the POST values
- $username = clean($_POST['username']);
- $password = clean($_POST['password']);
- //Input Validations
- if($username == '') {
- $errmsg_arr[] = 'Username missing';
- $errflag = true;
- }
- if($password == '') {
- $errmsg_arr[] = 'Password missing';
- $errflag = true;
- }
- //If there are input validations, redirect back to the login form
- if($errflag) {
- $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
- session_write_close();
- header("location: index.php");
- exit();
- }
- //Create query
- $qry="SELECT * FROM member WHERE username='$username' AND password='$password'";
- $result=mysqli_query($qry);
- //Check whether the query was successful or not
- if($result) {
- if(mysqli_num_rows($result) > 0) {
- //Login Successful
- session_regenerate_id();
- $member = mysqli_fetch_assoc($result);
- $_SESSION['SESS_MEMBER_ID'] = $member['mem_id'];
- $_SESSION['SESS_FIRST_NAME'] = $member['username'];
- $_SESSION['SESS_LAST_NAME'] = $member['password'];
- session_write_close();
- header("location: home.php");
- exit();
- }else {
- //Login failed
- $errmsg_arr[] = 'user name and password not found';
- $errflag = true;
- if($errflag) {
- $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
- session_write_close();
- header("location: index.php");
- exit();
- }
- }
- }else {
- die("Query failed");
- }
- ?>
- <?php
- //require_once('auth.php');
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <title>Untitled Document</title>
- <style type="text/css">
- <!--
- .style1 {
- font-size: 36px;
- font-weight: bold;
- }
- -->
- </style>
- </head>
- <body>
- <p align="center" class="style1">Login successfully </p>
- <p align="center">This page is the home, you can put some stuff here......</p>
- <p align="center"><a href="index.php">logout</a></p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement