diff --git a/README.md b/README.md index 3da4383..91a06cf 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# chatari +# PHP project template diff --git a/actions/registration.php b/actions/registration.php new file mode 100644 index 0000000..91f5a72 --- /dev/null +++ b/actions/registration.php @@ -0,0 +1,41 @@ +prepare('SELECT * FROM users WHERE login = :login'); +$q->execute(['login' => $login]); +$users = $q->fetchAll(); + +if (count($users) > 0) { + // user already exists + header('Location: /index.php?error=101'); + exit; +} + +$password = hash("sha256", $password); +// insert user into database +$q = $pdo->prepare('INSERT INTO users (login, nickname, password, active, timestamp, ip_addr) VALUES (:login, :nickname, :password, :active, :timestamp, :ip_addr)'); +$q->execute([ + 'login' => $login, + 'nickname' => $nickname, + 'password' => $password, + 'active' => 1, + 'timestamp' => time(), + 'ip_addr' => $_SERVER['REMOTE_ADDR'], +]); + +// redirect to index.php +header('Location: /index.php'); diff --git a/data/db.sqlite b/data/db.sqlite new file mode 100644 index 0000000..b8cffad Binary files /dev/null and b/data/db.sqlite differ diff --git a/include/db.php b/include/db.php new file mode 100644 index 0000000..91ee12e --- /dev/null +++ b/include/db.php @@ -0,0 +1,5 @@ + + diff --git a/include/header.php b/include/header.php new file mode 100644 index 0000000..28424b1 --- /dev/null +++ b/include/header.php @@ -0,0 +1,8 @@ + + + + + + <?php echo "$title"; ?> + + diff --git a/include/registration.php b/include/registration.php new file mode 100644 index 0000000..807d7d0 --- /dev/null +++ b/include/registration.php @@ -0,0 +1,26 @@ +
+ + +
+ + + +
+ + + +
+ "; + if ($error == 101) { + echo 'User already exists'; + } + echo ""; + } + ?> + + +
diff --git a/index.php b/index.php new file mode 100644 index 0000000..2bcb571 --- /dev/null +++ b/index.php @@ -0,0 +1,14 @@ + + +