login-system-met-mysql
Gesponsorde koppelingen
PHP script bestanden
index.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php include('options.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title ?></title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<center>
<h1>Login</h1>
<form action="login.php" method="post">
<p>Username: <input name="username" type="text" size="25" maxlength="25" /></p>
<p>Password: <input name="password" type="password" size="25" maxlength="25" /></p>
<p><input name="submit" type="submit" value="Log in" /></p>
<a href='register.php'>Register Account</a>
</form>
</center>
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title ?></title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<center>
<h1>Login</h1>
<form action="login.php" method="post">
<p>Username: <input name="username" type="text" size="25" maxlength="25" /></p>
<p>Password: <input name="password" type="password" size="25" maxlength="25" /></p>
<p><input name="submit" type="submit" value="Log in" /></p>
<a href='register.php'>Register Account</a>
</form>
</center>
</div>
</body>
</html>
login.php
Code (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
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
<?php include('options.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title ?></title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<?php
session_start();
$username = $_POST['username'];
$password = sha1($_POST['password']);
if($username && $password)
{
$connect = mysql_connect('localhost', 'root', '') or die ('Couldn\'t Connect');
mysql_select_db("website") or die ("Couldn\'t Find your database !");
$query = sprintf("SELECT id, username, password, nickname, date, email FROM users WHERE `username`='%s' AND `password`='%s'",
mysql_real_escape_string($username),
mysql_real_escape_string($password));
$rows = mysql_query($query);
$numrows = mysql_num_rows($rows);
if($numrows)
{
while($row = mysql_fetch_assoc($rows))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
$dbnickname = $row['nickname'];
$dbdate = $row['date'];
$dbemail = $row['email'];
}
echo("<p>Welcome back $dbusername !</p> <p>as nickname: $dbnickname</p><p>Account Registered at: $dbdate</p>");
echo("<p>Your Email address: $dbemail</p>");
echo("<a href='logout.php'>Logout</a>");
$_SESSION['username']=$dbusername;
}
else
die("Username or Password is wrong!");
}
?>
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title ?></title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<?php
session_start();
$username = $_POST['username'];
$password = sha1($_POST['password']);
if($username && $password)
{
$connect = mysql_connect('localhost', 'root', '') or die ('Couldn\'t Connect');
mysql_select_db("website") or die ("Couldn\'t Find your database !");
$query = sprintf("SELECT id, username, password, nickname, date, email FROM users WHERE `username`='%s' AND `password`='%s'",
mysql_real_escape_string($username),
mysql_real_escape_string($password));
$rows = mysql_query($query);
$numrows = mysql_num_rows($rows);
if($numrows)
{
while($row = mysql_fetch_assoc($rows))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
$dbnickname = $row['nickname'];
$dbdate = $row['date'];
$dbemail = $row['email'];
}
echo("<p>Welcome back $dbusername !</p> <p>as nickname: $dbnickname</p><p>Account Registered at: $dbdate</p>");
echo("<p>Your Email address: $dbemail</p>");
echo("<a href='logout.php'>Logout</a>");
$_SESSION['username']=$dbusername;
}
else
die("Username or Password is wrong!");
}
?>
</div>
</body>
</html>
logout.php
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
session_start();
unset($_SESSION['username']);
echo ("You have been successfully logged out! You will be redirected to the main page");
header('Location: http://localhost/');
?>
session_start();
unset($_SESSION['username']);
echo ("You have been successfully logged out! You will be redirected to the main page");
header('Location: http://localhost/');
?>
options.php
register.php
Code (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php include('options.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title ?>/title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<?php
if(get_magic_quotes_gpc()) {
$_GET = strip_slashes_deep($_GET);
$_POST = strip_slashes_deep($_POST);
}
function strip_slashes_deep($data) {
if(is_array($data)) {
foreach ($data as $key => $value) {
$data[$key] = strip_slashes_deep($value);
}
return $data;
}
else
{
return stripslashes($data);
}
}
$submit = $_POST['submit'];
$nickname = $_POST['nickname'];
$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$date = date("Y-m-d");
if(strlen($username) > 25 || strlen($nickname) > 25)
{
echo "Maximum Limit for Username and Nickname is 25 characters!";
}
if ($submit)
{
if ($nickname&&$username&&$password&&$password2)
{
if($password == $password2)
{
if(strlen($username) > 25 || strlen($nickname) > 25)
{
echo "Username and Nickname maximum is 25 characters";
}
else
{
if(strlen($password) > 25 || strlen($password) < 6)
{
echo "Password must be between 6 - 25 characters!";
}
else
{
//encrypt password
$password = sha1($password);
$password2 = sha1($password2);
//Register the user!
$connection = mysql_connect('localhost', 'root', '') or die ("Could not connect to the database server!");
mysql_select_db("website", $connection) or die ("Could not connect to the database");
$register = sprintf("INSERT INTO users VALUES('', '%s', '%s', '%s', '%s')",
mysql_real_escape_string($username),
mysql_real_escape_string($password),
mysql_real_escape_string($nickname),
mysql_real_escape_string($date));
mysql_query($register);
die("Successfully registered please <a href='index.php'>Log in</a>!");
}
}
}
else
echo "Password does not match!";
}
else
echo "Please fill in all fields!";
}
?>
<center>
<h1>Register</h1>
<form action="register.php" method="post" id="register">
<fieldset>
<p>Username: <input name="username" type="text" value="<?php echo $username; ?>" size="25" maxlength="25" /></p>
<p>Password: <input name="password" type="password" size="25" maxlength="25" /></p>
<p>Repeat Password: <input name="password2" type="password" size="25" maxlength="25" /></p>
<p>Nick Name: <input name="nickname" type="text" value="<?php echo $nickname; ?>" size="25" maxlength="25" /></p>
<input name="submit" type="submit" value="Register" />
</fieldset>
</form>
</center>
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title ?>/title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<?php
if(get_magic_quotes_gpc()) {
$_GET = strip_slashes_deep($_GET);
$_POST = strip_slashes_deep($_POST);
}
function strip_slashes_deep($data) {
if(is_array($data)) {
foreach ($data as $key => $value) {
$data[$key] = strip_slashes_deep($value);
}
return $data;
}
else
{
return stripslashes($data);
}
}
$submit = $_POST['submit'];
$nickname = $_POST['nickname'];
$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$date = date("Y-m-d");
if(strlen($username) > 25 || strlen($nickname) > 25)
{
echo "Maximum Limit for Username and Nickname is 25 characters!";
}
if ($submit)
{
if ($nickname&&$username&&$password&&$password2)
{
if($password == $password2)
{
if(strlen($username) > 25 || strlen($nickname) > 25)
{
echo "Username and Nickname maximum is 25 characters";
}
else
{
if(strlen($password) > 25 || strlen($password) < 6)
{
echo "Password must be between 6 - 25 characters!";
}
else
{
//encrypt password
$password = sha1($password);
$password2 = sha1($password2);
//Register the user!
$connection = mysql_connect('localhost', 'root', '') or die ("Could not connect to the database server!");
mysql_select_db("website", $connection) or die ("Could not connect to the database");
$register = sprintf("INSERT INTO users VALUES('', '%s', '%s', '%s', '%s')",
mysql_real_escape_string($username),
mysql_real_escape_string($password),
mysql_real_escape_string($nickname),
mysql_real_escape_string($date));
mysql_query($register);
die("Successfully registered please <a href='index.php'>Log in</a>!");
}
}
}
else
echo "Password does not match!";
}
else
echo "Please fill in all fields!";
}
?>
<center>
<h1>Register</h1>
<form action="register.php" method="post" id="register">
<fieldset>
<p>Username: <input name="username" type="text" value="<?php echo $username; ?>" size="25" maxlength="25" /></p>
<p>Password: <input name="password" type="password" size="25" maxlength="25" /></p>
<p>Repeat Password: <input name="password2" type="password" size="25" maxlength="25" /></p>
<p>Nick Name: <input name="nickname" type="text" value="<?php echo $nickname; ?>" size="25" maxlength="25" /></p>
<input name="submit" type="submit" value="Register" />
</fieldset>
</form>
</center>
</div>
</body>
</html>
style.css
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
@charset "utf-8";
/* CSS Document */
#container {
width:800px;
height:800px;
margin:0 auto;
}
#register {
width:350px;
height:500px;
}
/* CSS Document */
#container {
width:800px;
height:800px;
margin:0 auto;
}
#register {
width:350px;
height:500px;
}
SQL voor de database
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(30) NOT NULL,
`password` varchar(50) NOT NULL,
`nickname` varchar(30) NOT NULL,
`date` date NOT NULL,
`email` varchar(200) NOT NULL,
`status` int(5) NOT NULL DEFAULT '0',
`online` int(1) NOT NULL,
`LastIP` varchar(20) NOT NULL,
`registerIP` varchar(20) NOT NULL,
PRIMARY KEY (`id`,`username`)
) ENGINE=MyISAM AUTO_INCREMENT=46 DEFAULT CHARSET=latin1;
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(30) NOT NULL,
`password` varchar(50) NOT NULL,
`nickname` varchar(30) NOT NULL,
`date` date NOT NULL,
`email` varchar(200) NOT NULL,
`status` int(5) NOT NULL DEFAULT '0',
`online` int(1) NOT NULL,
`LastIP` varchar(20) NOT NULL,
`registerIP` varchar(20) NOT NULL,
PRIMARY KEY (`id`,`username`)
) ENGINE=MyISAM AUTO_INCREMENT=46 DEFAULT CHARSET=latin1;