forked from thedevdojo/php-login-script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
53 lines (37 loc) · 1007 Bytes
/
index.php
File metadata and controls
53 lines (37 loc) · 1007 Bytes
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
<?php
session_start();
require 'database.php';
if( isset($_SESSION['user_id']) ){
$records = $conn->prepare('SELECT id,email,password FROM users WHERE id = :id');
$records->bindParam(':id', $_SESSION['user_id']);
$records->execute();
$results = $records->fetch(PDO::FETCH_ASSOC);
$user = NULL;
if( count($results) > 0){
$user = $results;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Welcome to your Web App</title>
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
<link href='http://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="header">
<a href="/">Your App Name</a>
</div>
<?php if( !empty($user) ): ?>
<br />Welcome <?= $user['email']; ?>
<br /><br />You are successfully logged in!
<br /><br />
<a href="logout.php">Logout?</a>
<?php else: ?>
<h1>Please Login or Register</h1>
<a href="login.php">Login</a> or
<a href="register.php">Register</a>
<?php endif; ?>
</body>
</html>