-
Notifications
You must be signed in to change notification settings - Fork 0
/
registerCheck.php
52 lines (52 loc) · 1.1 KB
/
registerCheck.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
<!DOCTYPE html>
<head>
<meta charset="utf-8"/>
<title>RegisterCheck</title>
<style type="text/css">
body{
width: 760px; /* how wide to make your web page */
background-color: teal; /* what color to make the background */
margin: 0 auto;
padding: 0;
font:12px/16px Verdana, sans-serif; /* default font */
}
div#main{
background-color: #FFF;
margin: 0;
padding: 10px;
}
</style>
</head>
<body><div id="main">
<form action="login.php" method="GET">
<p>
<input type="submit" value="Back" />
</p>
</form>
<?php
$username = $_GET['username'];
if(!preg_match('/^[\w_\.\-]+$/', $username) ){
echo "Invalid username, username should only be consisted by letters and numbers.";
exit;
}
$existed = false;
$h = fopen("users.txt", "r");
while( !feof($h) ){
$record = trim(fgets($h));
if ($username == $record) {
$existed = true;
}
}
fclose($h);
if ($existed) {
echo "Username already exists.";
exit;
} else {
file_put_contents("users.txt","\n".$username,FILE_APPEND);
echo "Registered successfully.";
mkdir("$username", 0777, true);
exit;
}
?>
</div></body>
</html>