-
Notifications
You must be signed in to change notification settings - Fork 1
/
logincheck.php
70 lines (56 loc) · 1.59 KB
/
logincheck.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?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;
}
?>