-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
133 lines (105 loc) · 3.57 KB
/
signup.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
// include configuration file
include('config.php');
// connect to the database
$db = mysqli_connect ($db_host, $db_user, $db_password, $db_name) OR die ('Could not connect to MySQL: ' . mysqli_connect_error());
// continue session
session_start();
// if the form has been submitted
if(isset($_POST['submit']))
{
// create an empty error array
$error = array();
// check for a nickname
if(empty($_POST['nickname']))
{
$error['nickname'] = 'Pflichtfeld';
}
// check for a email
if(empty($_POST['email']))
{
$error['email'] = 'Pflichtfeld';
} else {
// check to see if email address is unique
$sql = "SELECT user_id FROM users WHERE email = '{$_POST['email']}'";
$result = mysqli_query($db, $sql);
if(mysqli_num_rows($result) > 0)
{
$error['email'] = 'Es gibt bereits einen Benutzer mit dieser E-Mail!';
}
}
// check for a password
if(empty($_POST['userpass']))
{
$error['userpass'] = 'Pflichtfeld';
}
// if there are no errors
if(sizeof($error) == 0)
{
// insert user into the users table
$sql = "INSERT INTO users (
user_id,
nickname,
email,
userpass,
signupdate
) VALUES (
null,
'{$_POST['nickname']}',
'{$_POST['email']}',
sha1('{$_POST['userpass']}'),
NOW()
)";
$result = mysqli_query($db, $sql);
// obtain user_id from table
$user_id = mysqli_insert_id($db);
// send a signup e-mail to user
$webmaster = 'name <[email protected]>'; // from email
$message = "Hallo {$_POST['nickname']},\n";
$message = $message . "die Registrierung bei yourdomain.com war erfolgreich!\n"; // change domain
$headers = "Content-type: text/plain\n";
mail($_POST['email'], 'Registrierung erfolgreich', $message, "From: $webmaster");
mail($webmaster, 'Neue Registrierung', "{$_POST['nickname']} hat sich mit der E-Mailadresse {$_POST['email']} bei yourdomain.com regestriert.", "From: {$_POST['nickname']} <{$_POST['email']}>"); // change domain
// append user_id to session array
$_SESSION['user_id'] = $user_id;
$_SESSION['nickname'] = $_POST['nickname'];
// redirect user to profile page
header("Location: profile.php");
exit();
}
}
?>
<!-- HTML -->
<!-- top navigation -->
<?php include('header.php'); ?>
<!-- content -->
<div class="container" style="margin-top: 65px">
<h2 class="text-primary">Registrierung</h2>
<p class="text-muted">Mit Nickname, E-Mail und Passwort regestrieren:</p>
<!-- signup form -->
<form method="post" action="signup.php">
<!-- first name -->
<div class="form-group">
<input name="nickname" placeholder="Nickname" type="text" value="<?php echo $_POST['nickname']; ?>" class="form-control" />
<span class="text-danger"><?php echo $error['nickname']; ?></span>
</div>
<!-- e-mail -->
<div class="form-group">
<input name="email" type="text" placeholder="E-Mail" value="<?php echo $_POST['email']; ?>" class="form-control" />
<span class="text-danger"><?php echo $error['email']; ?></span>
</div>
<!-- password -->
<div class="form-group">
<input name="userpass" placeholder="Passwort" type="password" class="form-control" />
<span class="text-danger"><?php echo $error['userpass']; ?></span>
</div>
<!-- submit button -->
<div class="form-group">
<input name="submit" type="submit" value="Registrieren" class="btn btn-primary" />
</div>
</form>
<!-- sign in link -->
<p>Hast du schon einen Account? Dann hier <a href="signin.php"><i class="fa fa-sign-in"></i>anmelden</a>!</p>
</div>
</body>
</html>