summaryrefslogtreecommitdiff
path: root/signin.php
diff options
context:
space:
mode:
Diffstat (limited to 'signin.php')
-rw-r--r--signin.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/signin.php b/signin.php
new file mode 100644
index 0000000..287eeda
--- /dev/null
+++ b/signin.php
@@ -0,0 +1,60 @@
+<?php
+
+include_once 'includes/db_inc.php';
+include_once 'header.php';
+
+echo '<section><h2>Sign in</h2>';
+
+if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ echo '
+ <form action="" method="post">
+ <label for="user_name">Username: </label><br>
+ <input type="text" name="user_name"><br>
+ <label for="user_pass">Password: </label><br>
+ <input type="password" name="user_pass"><br>
+ <input type="submit" name="submit">
+ </form>
+ ';
+} else {
+ $errors = array();
+
+ if (!isset($_POST['user_name'])) {
+ $errors[] = 'Please provide a username.';
+ }
+
+ if (!isset($_POST['user_pass'])) {
+ $errors[] = 'Please provide a password.';
+ }
+
+ if (!empty($errors)) {
+ echo 'Please check the following problems: <ul>';
+ foreach ($errors as $err) {
+ echo '<li>' . $err . '</li>';
+ }
+ echo '</ul>';
+ } else {
+ $sql = "SELECT user_id, user_name FROM users WHERE user_name = '" . mysqli_real_escape_string($dbc, $_POST['user_name']) . "' AND user_pass = '" . sha1($_POST['user_pass']) ."'";
+ $result = mysqli_query($dbc, $sql);
+
+ if (!$result) {
+ echo 'An error occurred while signing in.';
+ echo mysqli_error($dbc);
+ } else {
+ if (mysqli_num_rows($result) == 0) {
+ echo 'There is no user with that username/password combination! Please try again';
+ } else {
+ $_SESSION['signed_in'] = true;
+
+ while ($row = mysqli_fetch_assoc($result)) {
+ $_SESSION['user_id'] = $row['user_id'];
+ $_SESSION['user_name'] = $row['user_name'];
+ }
+
+ echo 'You are now signed in as ' . $_SESSION['user_name'];
+ }
+ }
+ }
+}
+
+echo '</section>';
+include_once 'footer.php'; \ No newline at end of file