Skip to content

Commit

Permalink
Added all needed files
Browse files Browse the repository at this point in the history
  • Loading branch information
CodHeK committed May 27, 2017
0 parents commit 2d613ef
Show file tree
Hide file tree
Showing 6 changed files with 339 additions and 0 deletions.
80 changes: 80 additions & 0 deletions dosignup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

if(isset($_POST['signup'])) {
define('MyConst', TRUE);
}

if(!defined('MyConst')) {
echo '<script language="javascript">';
echo 'alert("Access Denied");';
echo '</script>';
header("Refresh: 1; url=index.php");
}

else {
if(!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['password'])) {
$name = htmlentities($_POST['name']);
$email = htmlentities($_POST['email']);
$pass = md5(htmlentities($_POST['password']));
}
else {
echo '<script language="javascript">';
echo 'alert("Enter All the Details first !");';
echo '</script>';
header("Location:index.php");
}


$servername = "localhost";
$username = "root";
$password = "";
$dbname = "pdologin";
$tbname = "userDetails";

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $conn->prepare('SELECT * FROM userDetails WHERE email = :email');

$stmt->execute(['email' => $email]);

$user = $stmt->fetch(PDO::FETCH_ASSOC);

if($user != NULL) {
echo '<script language="javascript">';
echo 'alert("Email Already Registered !");';
echo '</script>';
header("Refresh: 1; url=index.php");
}
else {
$sql = $conn->prepare("INSERT INTO $tbname (name,email,password) VALUES (:name,:email,:password)");

$do = $sql->execute(['name' => $name, 'email' => $email, 'password' => $pass]);

if($do) {
echo '<script language="javascript">';
echo 'alert("Signed up Successfully !");';
echo '</script>';
header("Refresh: 1; url=login.php");
}
else {
echo '<script language="javascript">';
echo 'alert("Looks like there is some Error !");';
echo '</script>';
header("Refresh: 1; url=index.php");
}
}
}
catch(PDOException $e) {
echo '<script language="javascript">';
echo '$sql . "<br>" . $e->getMessage();';
echo '</script>';
header("Refresh: 1; url=index.php");
}

$conn = NULL;
}

?>
59 changes: 59 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
session_start();
if(isset($_SESSION['user'])) {
header('Location: welcome.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<title>HomePage</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link href="https://fonts.googleapis.com/css?family=Changa:200|Source+Sans+Pro:200" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<style type="text/css">
body {
font-family: 'Source Sans Pro', sans-serif;
font-weight: 700;
}
</style>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">PDOphp</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="login.php">LOG IN</a></li>
<li><a href="index.php">SIGN UP</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>

<div id="content" style="margin: 0 auto;text-align: center;">
<h1>SIGN UP</h1>
<br>
<form method="POST" action="dosignup.php">
<div class="form-group col-md-6" style="margin-left: 27%;">
<input type="text" name="name" placeholder="Enter Username" class="form-control"><br>
<input type="email" name="email" placeholder="Enter Email" class="form-control"><br>
<input type="password" name="password" placeholder="Enter Password" class="form-control"><br>
<input type="submit" class="btn btn-defaut" name="signup" value="SIGN UP">
</div>
</form>
</div>
</body>
</html>
59 changes: 59 additions & 0 deletions login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
session_start();
if(isset($_SESSION['user'])) {
header('Location: welcome.php');
}
?>

<!DOCTYPE html>
<html>
<head>
<title>HomePage</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link href="https://fonts.googleapis.com/css?family=Changa:200|Source+Sans+Pro:200" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<style type="text/css">
body {
font-family: 'Source Sans Pro', sans-serif;
font-weight: 700;
}
</style>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">PDOphp</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="login.php">LOG IN</a></li>
<li><a href="index.php">SIGN UP</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>

<div id="content" style="margin: 0 auto;text-align: center;">
<h1>LOG IN</h1>
<br>
<form method="POST" action="logincheck.php">
<div class="form-group col-md-6" style="margin-left: 27%;">
<input type="text" name="name" placeholder="Enter Username" class="form-control"><br>
<input type="password" name="password" placeholder="Enter Password" class="form-control"><br>
<input type="submit" class="btn btn-defaut" name="login" value="LOG IN">
</div>
</form>
</div>
</body>
</html>
70 changes: 70 additions & 0 deletions logincheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
session_start();

if(isset($_POST['login'])) {
define('MyConst', TRUE);
}

if(!defined('MyConst')) {
echo '<script language="javascript">';
echo 'alert("Access Denied");';
echo '</script>';
header("Refresh: 1; url=login.php");
}
else {
if(!empty($_POST['name']) && !empty($_POST['password'])) {
$name = htmlentities($_POST['name']);
$pass = md5(htmlentities($_POST['password']));
}
else {
echo '<script language="javascript">';
echo 'alert("Enter All the Details first !");';
echo '</script>';
header("Location:login.php");
}


$servername = "localhost";
$username = "root";
$password = "";
$dbname = "pdologin";
$tbname = "userDetails";

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $conn->prepare("SELECT * FROM userDetails WHERE name = :name AND password = :password");

$stmt->execute(['name' => $name, 'password' => $pass]);

$user = $stmt->fetch(PDO::FETCH_ASSOC);

if($user != NULL) {
$id = $user['id'];
$_SESSION['user'] = $name;
$_SESSION['id'] = $id;
$_SESSION['isactive'] = true;
header("Location:welcome.php");
}
else {
echo '<script language="javascript">';
echo 'alert("Check Your Username/ Password !");';
echo '</script>';
header("Refresh: 1; url=login.php");
}


}
catch(PDOException $e) {
echo '<script language="javascript">';
echo '$sql . "<br>" . $e->getMessage();';
echo '</script>';
header("Location:login.php");
}

$conn = NULL;
}
?>

15 changes: 15 additions & 0 deletions logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
session_start();
if(!isset($_SESSION['user'])) {
echo '<script language="javascript">';
echo 'alert("First Login!");';
echo '</script>';
header("Location:login.php");
exit();
}
else {
session_unset();
session_destroy();
header('Location:login.php');
}
?>
56 changes: 56 additions & 0 deletions welcome.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

session_start();
if(!isset($_SESSION['user'])) {
echo '<script language="javascript">';
echo 'alert("First Login!");';
echo '</script>';
header("Location:login.php");
exit();
}
else {
$id = $_SESSION['id'];
$name = $_SESSION['user'];
}
?>

<!DOCTYPE html>
<html>
<head>
<title>Welcome</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link href="https://fonts.googleapis.com/css?family=Changa:200|Source+Sans+Pro:200" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<style type="text/css">
body {
font-family: 'Source Sans Pro', sans-serif;
font-weight: 700;
}
</style>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">PDOphp</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="logout.php">LOG OUT</a></li>
<li style="color: black;font-weight: 700;border: 1px solid black;"><a><?php echo $name ?></a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</body>
</html>

0 comments on commit 2d613ef

Please sign in to comment.