From 552e9b7a492f47037e7e3b11204a5441ff01c71c Mon Sep 17 00:00:00 2001 From: Ivan Pomykacz Date: Wed, 2 Apr 2025 15:47:13 +0200 Subject: [PATCH] registracni formular --- README.md | 2 +- actions/registration.php | 41 +++++++++++++++++++++++++++++++++++++++ data/db.sqlite | Bin 0 -> 12288 bytes include/db.php | 5 +++++ include/footer.php | 3 +++ include/header.php | 8 ++++++++ include/registration.php | 26 +++++++++++++++++++++++++ index.php | 14 +++++++++++++ 8 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 actions/registration.php create mode 100644 data/db.sqlite create mode 100644 include/db.php create mode 100644 include/footer.php create mode 100644 include/header.php create mode 100644 include/registration.php create mode 100644 index.php 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 0000000000000000000000000000000000000000..b8cffad868cce48c162aa5567f3c380aab89ad41 GIT binary patch literal 12288 zcmeI&J#X4T7zgk(kXDZ55Q)J{rJm>lB0@eJzb#cs#ehmkO3A>|^n733mMJXZVKp$0o zJcOYyY7ZTK-u3?#2c#>ArAJkczLTRLx{u{#}O zR`6t@@|%VJZF-ffn_IOK``zm6$)G}QI;6Cj$tKNKg_^4^9iLC>_;NI&7n9*xe=?(Q1~b~foSqNIy1?0B zJU!V>S*+*Ts!0p=xo9yrYX6>BW;Z;~KdraAY&jt4?d4aQxZbV!u{;+=_EBf|7gZK7 zvZcxkzT7;L&o)ARqt%2tWV=5P$##AOHafKmY;|cwaS1 z+H=0hgmM!ZIf017)KQMZQ^r{;JkO0%9tIwd z-5?HKPed}&cSJ9ZJ)VY4CM*hMpkk-LE25uq%-pc+=#A;`u%W}WEd2pE=Xwph|K^SQ mPoj4O1Rwwb2tWV=5P$##AOHafKmY>&lYnVdZKHhQq52D=uC>ts literal 0 HcmV?d00001 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 @@ + + +