-
Notifications
You must be signed in to change notification settings - Fork 1
/
loged.php
65 lines (51 loc) · 1.62 KB
/
loged.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
<?php
/*** begin the session ***/
session_start();
if(!isset($_SESSION['user_id']))
{
$message = 'You must be logged in to access this page';
}
else
{
try
{
/*** connect to database ***/
/*** mysql hostname ***/
$mysql_hostname = 'localhost';
/*** mysql username ***/
$mysql_username = 'root';
/*** mysql password ***/
$mysql_password = '';
/*** database name ***/
$mysql_dbname = 'noor';
/*** select the users name from the database ***/
$dbh = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);
/*** $message = a message saying we have connected ***/
/*** set the error mode to excptions ***/
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/*** prepare the insert ***/
$stmt = $dbh->prepare("SELECT username FROM users
WHERE user_id = :user_id");
/*** bind the parameters ***/
$stmt->bindParam(':user_id', $_SESSION['user_id'], PDO::PARAM_INT);
/*** execute the prepared statement ***/
$stmt->execute();
/*** check for a result ***/
$username = $stmt->fetchColumn();
/*** if we have no something is wrong ***/
if($username == false)
{
$message = 'Access Error';
}
else
{
$message = 'Welcome '.$username;
}
}
catch (Exception $e)
{
/*** if we are here, something is wrong in the database ***/
$message = 'We are unable to process your request. Please try again later"';
}
}
?>