move php functions into functions file
This commit is contained in:
parent
137ce0be7e
commit
718398d824
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
require('db.php');
|
||||||
|
function login ()
|
||||||
|
{
|
||||||
|
session_start();
|
||||||
|
if (isset($_REQUEST['username'])) {
|
||||||
|
//Checking is user existing in the database or not
|
||||||
|
global $con;
|
||||||
|
$username = stripslashes($_REQUEST['username']);
|
||||||
|
//escapes special characters in a string
|
||||||
|
$username = mysqli_real_escape_string($con,$username);
|
||||||
|
$password = stripslashes($_REQUEST['password']);
|
||||||
|
$password = mysqli_real_escape_string($con,$password);
|
||||||
|
$query = "SELECT * FROM users WHERE userLogin='$username'
|
||||||
|
and userPass='$password'";
|
||||||
|
$result = mysqli_query($con,$query) or die(mysql_error());
|
||||||
|
$rows = mysqli_num_rows($result);
|
||||||
|
if ($rows==1) {
|
||||||
|
$_SESSION['username'] = $username;
|
||||||
|
// Redirect user to home.php
|
||||||
|
header("Location: home.php");
|
||||||
|
} else {
|
||||||
|
echo "<h3>Username/password is incorrect.</h3>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If form submitted, insert values into the database.
|
||||||
|
function register ()
|
||||||
|
{
|
||||||
|
if (isset($_REQUEST['username'])) {
|
||||||
|
global $con;
|
||||||
|
// removes backslashes
|
||||||
|
$username = stripslashes($_REQUEST['username']);
|
||||||
|
//escapes special characters in a string
|
||||||
|
$username = mysqli_real_escape_string($con,$username);
|
||||||
|
$email = stripslashes($_REQUEST['email']);
|
||||||
|
$email = mysqli_real_escape_string($con,$email);
|
||||||
|
$password = stripslashes($_REQUEST['password']);
|
||||||
|
$password = mysqli_real_escape_string($con,$password);
|
||||||
|
$query = "INSERT into users (userLogin, userPass, userEmail)
|
||||||
|
VALUES ('$username', '$password', '$email')";
|
||||||
|
$result = mysqli_query($con,$query);
|
||||||
|
if ($result) {
|
||||||
|
echo "<div class='form'>
|
||||||
|
<h3>You are registered successfully.</h3>
|
||||||
|
<br/>Click here to <a href='index.php'>Login</a></div>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
13
index.php
13
index.php
|
@ -1,3 +1,6 @@
|
||||||
|
<?php
|
||||||
|
include 'functions.php';
|
||||||
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
@ -20,12 +23,12 @@
|
||||||
<form action="" method="post" name="login">
|
<form action="" method="post" name="login">
|
||||||
<input type="text" name="username" placeholder="Username" required />
|
<input type="text" name="username" placeholder="Username" required />
|
||||||
<input type="password" name="password" placeholder="Password" required />
|
<input type="password" name="password" placeholder="Password" required />
|
||||||
<input name="submit" type="submit"/>
|
<input name="submit" type="submit" value="Login"/>
|
||||||
<?php
|
|
||||||
include 'login.php';
|
|
||||||
?>
|
|
||||||
</form>
|
</form>
|
||||||
<p>Not registered yet? <a href='registrationindex.php'>Register Here</a></p>
|
<p>Not registered yet? <a href='registration.php'>Register Here</a></p>
|
||||||
|
<?php
|
||||||
|
login();
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
27
login.php
27
login.php
|
@ -1,27 +0,0 @@
|
||||||
<?php
|
|
||||||
require('db.php');
|
|
||||||
session_start();
|
|
||||||
// If form submitted, insert values into the database.
|
|
||||||
if (isset($_POST['username'])) {
|
|
||||||
// removes backslashes
|
|
||||||
$username = stripslashes($_REQUEST['username']);
|
|
||||||
//escapes special characters in a string
|
|
||||||
$username = mysqli_real_escape_string($con,$username);
|
|
||||||
$password = stripslashes($_REQUEST['password']);
|
|
||||||
$password = mysqli_real_escape_string($con,$password);
|
|
||||||
//Checking is user existing in the database or not
|
|
||||||
$query = "SELECT * FROM `users` WHERE username='$username'
|
|
||||||
and password='".md5($password)."'";
|
|
||||||
$result = mysqli_query($con,$query) or die(mysql_error());
|
|
||||||
$rows = mysqli_num_rows($result);
|
|
||||||
if ($rows==1) {
|
|
||||||
$_SESSION['username'] = $username;
|
|
||||||
// Redirect user to home.php
|
|
||||||
header("Location: home.php");
|
|
||||||
} else {
|
|
||||||
echo "<div class='form'>
|
|
||||||
<h3>Username/password is incorrect.</h3>
|
|
||||||
<br/>Click here to <a href='login.php'>Login</a></div>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,45 +1,37 @@
|
||||||
|
<?php
|
||||||
|
include 'functions.php';
|
||||||
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<!-- enable utf-8 encoding for umlauts etc.-->
|
||||||
<title>Registration</title>
|
<meta charset="utf-8">
|
||||||
<link rel="stylesheet" href="css/loginstyle.css" />
|
<!-- Description of what this dose -->
|
||||||
|
<meta name ="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<!-- link to the default css file -->
|
||||||
|
<link rel="stylesheet" href="css/loginstyle.css"/>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<?php
|
<div>
|
||||||
require('db.php');
|
<div>
|
||||||
// If form submitted, insert values into the database.
|
<header>
|
||||||
if (isset($_REQUEST['username'])) {
|
<!-- The title begins here -->
|
||||||
// removes backslashes
|
<h1>WebShop NeXt</h1>
|
||||||
$username = stripslashes($_REQUEST['username']);
|
</header>
|
||||||
//escapes special characters in a string
|
</div>
|
||||||
$username = mysqli_real_escape_string($con,$username);
|
<div class="form">
|
||||||
$email = stripslashes($_REQUEST['email']);
|
<h1>Registration</h1>
|
||||||
$email = mysqli_real_escape_string($con,$email);
|
<form name="registration" action="" method="post">
|
||||||
$password = stripslashes($_REQUEST['password']);
|
<input type="text" name="username" placeholder="Username" required />
|
||||||
$password = mysqli_real_escape_string($con,$password);
|
<input type="email" name="email" placeholder="Email" required />
|
||||||
$trn_date = date("Y-m-d H:i:s");
|
<input type="password" name="password" placeholder="Password" required />
|
||||||
$query = "INSERT into `users` (username, password, email, trn_date)
|
<input type="submit" name="submit" value="Register"/>
|
||||||
VALUES ('$username', '".md5($password)."',
|
</form>
|
||||||
'$email', '$trn_date')";
|
<?php
|
||||||
$result = mysqli_query($con,$query);
|
register();
|
||||||
if ($result) {
|
?>
|
||||||
echo "<div class='form'>
|
</div>
|
||||||
<h3>You are registered successfully.</h3>
|
|
||||||
<br/>Click here to <a href='login.php'>Login</a></div>";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
?>
|
|
||||||
<div class="form">
|
|
||||||
<h1>Registration</h1>
|
|
||||||
<form name="registration" action="" method="post">
|
|
||||||
<input type="text" name="username" placeholder="Username" required />
|
|
||||||
<input type="email" name="email" placeholder="Email" required />
|
|
||||||
<input type="password" name="password" placeholder="Password" required />
|
|
||||||
<input type="submit" name="submit" value="Register" />
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
<?php } ?>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<!-- enable utf-8 encoding for umlauts etc.-->
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<!-- Description of what this dose -->
|
|
||||||
<meta name ="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<!-- link to the default css file -->
|
|
||||||
<link rel="stylesheet" href="css/loginstyle.css"/>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
<header>
|
|
||||||
<!-- The title begins here -->
|
|
||||||
<h1>WebShop NeXt</h1>
|
|
||||||
<!-- The title begins here -->
|
|
||||||
|
|
||||||
<!-- The sidebar naviagtion begins here -->
|
|
||||||
<nav>
|
|
||||||
<!--Registration-->
|
|
||||||
<?php
|
|
||||||
include 'registration.php';
|
|
||||||
?>
|
|
||||||
<!--Registration end-->
|
|
||||||
</nav>
|
|
||||||
<!-- The sidebar naviagtion ends here -->
|
|
||||||
</header>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,31 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<!-- enable utf-8 encoding for umlauts etc.-->
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<!-- Description of what this dose -->
|
|
||||||
<meta name ="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<!-- link to the default css file -->
|
|
||||||
<link rel="stylesheet" href="css/stylesheet.css"/>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
<header>
|
|
||||||
<!-- The sidebar naviagtion begins here -->
|
|
||||||
<nav>
|
|
||||||
<ul>
|
|
||||||
<li><a href="ticket.html">Ticket</a></li>
|
|
||||||
<li><a href="board.html">Board</a></li>
|
|
||||||
<li><a class="active" href="index.html">Home</a></li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
<!-- The sidebar naviagtion ends here -->
|
|
||||||
</header>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p>Some title</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue