mirror of
https://github.com/Dannecron/test-php-2015.git
synced 2025-12-25 13:52:33 +03:00
add sources
This commit is contained in:
26
src/activate.php
Executable file
26
src/activate.php
Executable file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
include ('bdcon.php');
|
||||
$patt = '[^0-9]';
|
||||
$replace = '';
|
||||
$hash = preg_replace($patt,$replace,$_GET['hash']);
|
||||
if ($hash!=""){
|
||||
$qe = mysqli_query($db,"Select uid from users where ehash='$hash'");
|
||||
$row = mysqli_fetch_array($qe);
|
||||
if (!empty($row['uid'])){
|
||||
$qe2 = mysqli_query($db, "update users set bel=true, ehash = '' where ehash = '$hash'");
|
||||
if ($qe2){
|
||||
mysqli_commit($db);
|
||||
echo "Активация аккаунта прошла успешно. Вернуться на <a href='index.php'>Главную страницу</a>.";
|
||||
}
|
||||
else{
|
||||
echo "Ошибка обновления.";
|
||||
}
|
||||
}
|
||||
else{
|
||||
echo "Ошибка.";
|
||||
}
|
||||
}
|
||||
else{
|
||||
echo "Ошибка. Неправильная ссылка.";
|
||||
}
|
||||
?>
|
||||
6
src/bdcon.php
Executable file
6
src/bdcon.php
Executable file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$db = mysqli_connect($_ENV['db_url'], $_ENV['db_username'], $_ENV['db_password'], "test");
|
||||
mysqli_query($db,"SET NAMES 'utf8'");
|
||||
mysqli_query($db,"SET CHARACTER SET 'utf8'");
|
||||
mysqli_query($db, "SET SESSION collation_connection = 'utf8_general_ci'");
|
||||
?>
|
||||
8
src/exit.php
Executable file
8
src/exit.php
Executable file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
session_start();
|
||||
if (!empty($_SESSION['id'])){
|
||||
unset($_SESSION['id']);
|
||||
unset($_SESSION['login']);
|
||||
}
|
||||
echo "Выход произведен. Перейдите на <a href='/index.php'>Главную страницу</a>";
|
||||
?>
|
||||
34
src/index.php
Executable file
34
src/index.php
Executable file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
session_start();
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="ru">
|
||||
|
||||
<head>
|
||||
<title>Главная страница</title>
|
||||
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table><tr>
|
||||
<td><a href="/index.php">Главная страница</a></td>
|
||||
<?php if (empty($_SESSION['id'])) {echo"<td><a href='/reg.php'>Регистрация</a></td>";}?>
|
||||
<?php if (empty($_SESSION['id'])) {echo"<td><a href='/log.php'>Вход в систему</a></td>";}?>
|
||||
<?php if (!empty($_SESSION['id'])) {echo"<td><a href='/lk.php'>Личный кабинет</a></td>";}?>
|
||||
<?php if (!empty($_SESSION['id'])){echo "<td><a href='exit.php'>Выход</a></td>";}?>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<?php
|
||||
if (empty($_SESSION['login']) or empty($_SESSION['id'])) {
|
||||
echo "Здравствуйте, гость. Пользуясь меню, совершите, пожалуйста, вход или регистрацию.";
|
||||
}
|
||||
else {
|
||||
echo "Вы вошли на сайт, как ".$_SESSION['login'].". Приятного времени суток.";
|
||||
}
|
||||
?>
|
||||
</p>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
27
src/inmon.php
Executable file
27
src/inmon.php
Executable file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
session_start();
|
||||
if (isset($_POST['sum'])){
|
||||
$sum = $_POST['sum'];
|
||||
if (is_numeric($sum)==false){
|
||||
exit ("Нужно ввести число <a href='lk.php'>Вернуться назад</a>.");
|
||||
}
|
||||
}
|
||||
if (empty($sum)){
|
||||
exit ("Нужно ввести число <a href='lk.php'>Вернуться назад</a>.");
|
||||
}
|
||||
if ($sum<0) { $sum=-$sum; }
|
||||
$uid = $_SESSION['id'];
|
||||
include("bdcon.php");
|
||||
mysqli_autocommit($db, false);
|
||||
$dt = date("d-m-Y H:i");
|
||||
$comm = "Приход. Пополнение на сайте.";
|
||||
$qe3 = mysqli_query($db, "Insert into history (uid,tdate,`inout`,`comm`) values($uid,STR_TO_DATE('$dt','%d-%m-%Y %H:%i'),$sum,'$comm')");
|
||||
if ($qe3) {
|
||||
mysqli_commit($db);
|
||||
echo "Все прошло успешно. Вернуться в <a href='lk.php'>Личный кабинет</a>.";
|
||||
}
|
||||
else {
|
||||
mysqli_rollback($db);
|
||||
echo "Произошла ошибка.";
|
||||
}
|
||||
?>
|
||||
110
src/lk.php
Executable file
110
src/lk.php
Executable file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
session_start();
|
||||
include ("bdcon.php");
|
||||
$uid = $_SESSION['id'];
|
||||
$res = mysqli_query($db, "select tdate, `inout`, `comm` from history where uid=$uid");
|
||||
$res2 = mysqli_query($db,"select sum(`inout`) as sum from history where uid=$uid group by uid");
|
||||
$row2 = mysqli_fetch_array($res2);
|
||||
$res3 = mysqli_query($db,"select bel from users where uid=$uid");
|
||||
$row3 = mysqli_fetch_array($res3);
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="ru">
|
||||
|
||||
<head>
|
||||
<title>Личный кабинет</title>
|
||||
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
|
||||
<script type="text/javascript">
|
||||
window.onload = function(){
|
||||
document.getElementById('togg').onclick = function(){
|
||||
openbox('box','box2','box3','togg');
|
||||
return false;
|
||||
}
|
||||
document.getElementById('togg2').onclick = function(){
|
||||
openbox('box2','box','box3','togg2');
|
||||
return false;
|
||||
}
|
||||
document.getElementById('togg3').onclick = function(){
|
||||
openbox('box3','box','box2','togg3');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function openbox(id1,id2,id3,toggler){
|
||||
var div = document.getElementById(id1);
|
||||
var div2 = document.getElementById(id2);
|
||||
var div3 = document.getElementById(id3);
|
||||
if (div.style.display == 'block'){
|
||||
div.style.display = 'none';
|
||||
}
|
||||
else{
|
||||
div.style.display = 'block';
|
||||
if (div2.style.display == 'block'){ div2.style.display = 'none'; }
|
||||
if (div3.style.display == 'block'){ div3.style.display = 'none'; }
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table><tr>
|
||||
<td><a href="/index.php">Главная страница</a></td>
|
||||
<td><a href="/lk.php">Личный кабинет</a></td>
|
||||
<?php if (!empty($_SESSION['id'])){
|
||||
echo "<td><a href='exit.php'>Выход</a></td>";
|
||||
}
|
||||
if (!$row3['bel']){
|
||||
echo "<td>Ваш аккаунт не активирован.</td>";
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
</table>
|
||||
<p>Ваш баланс лицевого счета: <?php if (empty($row2['sum'])){
|
||||
echo "0";
|
||||
}
|
||||
else{
|
||||
echo $row2['sum'];
|
||||
} ?></p>
|
||||
<table><tr>
|
||||
<td><button id="togg">Пополнить баланс</button></td>
|
||||
<td><button id="togg2">Посмотреть историю операций</button></td>
|
||||
<td><button id="togg3">Перевести средства</button></td>
|
||||
</tr></table>
|
||||
<div id="box" style="display: none;"><table width=30%>
|
||||
<tr><td colspan=2 align="center" style="font-size: 16pt;"><b>Пополнение баланса лицевого счета</b></td></tr>
|
||||
<form method="post" action="inmon.php">
|
||||
<tr><td>Введите сумму:</td><td align="center"><input type="text" name="sum" maxlength="7" required></td></tr>
|
||||
<tr><td colspan=2 align="center">
|
||||
<input type="submit" name="submit" value="Пополнить">
|
||||
</td></tr>
|
||||
</form>
|
||||
</table>
|
||||
</div>
|
||||
<div id="box2" style="display: none;"><table width=40%>
|
||||
<tr><td colspan=3 align="center" style="font-size: 16pt;"><b>История операций</b></td></tr>
|
||||
<?php
|
||||
$i=0;
|
||||
while ($row = mysqli_fetch_row($res)){
|
||||
echo "<tr align='center'><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td></tr>";
|
||||
$i++;
|
||||
}
|
||||
if ($i==0) { echo "<tr align='center'><td>Операций не производилось</td></tr>"; }
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
<div id="box3", style="display: none;"><table width=30%>
|
||||
<tr><td colspan=2 align="center" style="font-size: 16pt;"><b>Перевод средств другому пользователю</b></td></tr>
|
||||
<form method="post" action="trans.php">
|
||||
<tr><td>Имя пользователя:</td><td align="center">
|
||||
<input type="text" name="uname" required>
|
||||
</td></tr>
|
||||
<tr><td>Сумма:</td><td align="center"><input type="text" name="sum" maxlength="7" required></td></tr>
|
||||
<tr><td colspan=2 align="center">
|
||||
<input type="submit" name="submit" value="Перевести">
|
||||
</td></tr>
|
||||
</form>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
36
src/log.php
Executable file
36
src/log.php
Executable file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
session_start();
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="ru">
|
||||
|
||||
<head>
|
||||
<title>Вход в систему</title>
|
||||
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table><tr>
|
||||
<td><a href="/index.php">Главная страница</a></td>
|
||||
<td><a href="/reg.php">Регистрация</a></td>
|
||||
<td><a href="/log.php">Вход в систему</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
<form method="post" action="login.php">
|
||||
<tr>
|
||||
<td><b>Login</b>:</td>
|
||||
<td><input name="login" type="text" size=20 required></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Password</b>:</td>
|
||||
<td><input name="pass" type="password" size=20 required></td>
|
||||
</tr>
|
||||
<tr><td colspan=2 align="center">
|
||||
<input type="submit" name="submit" value="Login"></td>
|
||||
</tr></form>
|
||||
</table>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
45
src/login.php
Executable file
45
src/login.php
Executable file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
session_start();
|
||||
function confirmPassword($hash, $password)
|
||||
{
|
||||
return crypt($password, $hash) === $hash;
|
||||
}
|
||||
include ("bdcon.php");
|
||||
if (isset($_POST['login'])){
|
||||
$login = $_POST['login'];
|
||||
if ($login==''){
|
||||
unset($login);
|
||||
}
|
||||
}
|
||||
if (isset($_POST['pass'])) {
|
||||
$pass = $_POST['pass'];
|
||||
if ($pass==''){
|
||||
unset($pass);
|
||||
}
|
||||
}
|
||||
if (empty($login) or empty($pass)){
|
||||
exit ("Заполнены не все поля! Нужно ввести логин и пароль.");
|
||||
}
|
||||
$login = stripslashes($login);
|
||||
$login = htmlspecialchars($login);
|
||||
$pass = stripslashes($pass);
|
||||
$pass = htmlspecialchars($pass);
|
||||
$login = trim($login);
|
||||
$pass = trim($pass);
|
||||
|
||||
$result = mysqli_query($db, "Select * from users where login='$login'");
|
||||
$row = mysqli_fetch_array($result);
|
||||
if (empty($row['pass'])){
|
||||
exit ("Неверно введены логин или пароль.");
|
||||
}
|
||||
else{
|
||||
if (confirmPassword($row['pass'],$pass)){
|
||||
$_SESSION['login']=$row['login'];
|
||||
$_SESSION['id']=$row['uid'];
|
||||
echo "Вы успешно вошли на сайт. <a href='lk.php'>Личный кабинет</a>.";
|
||||
}
|
||||
else{
|
||||
exit ("Неверно введены логин или пароль.");
|
||||
}
|
||||
}
|
||||
?>
|
||||
41
src/reg.php
Executable file
41
src/reg.php
Executable file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
session_start();
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="ru">
|
||||
|
||||
<head>
|
||||
<title>Регистрация</title>
|
||||
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table><tr>
|
||||
<td><a href="/index.php">Главная страница</a></td>
|
||||
<td><a href="/reg.php">Регистрация</a></td>
|
||||
<td><a href="/log.php">Вход в систему</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
<form method="post" action="registration.php">
|
||||
<tr>
|
||||
<td><b>E-mail</b>:</td>
|
||||
<td><input name="em" type="email" size=50 required></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Login</b>:</td>
|
||||
<td><input name="lg" type="text" size=20 required></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Password</b>:</td>
|
||||
<td><input name="pass" type="password" size=20 required></td>
|
||||
</tr>
|
||||
<tr><td colspan=2 align="center">
|
||||
<input type="submit" name="submit" value="Registration"></td>
|
||||
</tr></form>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
73
src/registration.php
Executable file
73
src/registration.php
Executable file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
function hashPassword($password)
|
||||
{
|
||||
$salt = md5(uniqid('some_prefix', true));
|
||||
$salt = substr(strtr(base64_encode($salt), '+', '.'), 0, 22);
|
||||
return crypt($password, '$2a$08$' . $salt);
|
||||
}
|
||||
include ("bdcon.php");
|
||||
mysqli_autocommit($db, false);
|
||||
if (isset($_POST['lg'])){
|
||||
$login = $_POST['lg'];
|
||||
if ($login==''){
|
||||
unset($login);
|
||||
}
|
||||
}
|
||||
if (isset($_POST['pass'])) {
|
||||
$pass = $_POST['pass'];
|
||||
if ($pass==''){
|
||||
unset($pass);
|
||||
}
|
||||
}
|
||||
if (isset($_POST['em'])) {
|
||||
$email = $_POST['em'];
|
||||
if ($email==''){
|
||||
unset($email);
|
||||
}
|
||||
}
|
||||
if (empty($login) or empty($pass) or empty($email)){
|
||||
exit ("Заполнены не все поля! Нужно ввести всю информацию.");
|
||||
}
|
||||
$login = stripslashes($login);
|
||||
$login = htmlspecialchars($login);
|
||||
$pass = stripslashes($pass);
|
||||
$pass = htmlspecialchars($pass);
|
||||
$email = stripslashes($email);
|
||||
$email = htmlspecialchars($email);
|
||||
$login = trim($login);
|
||||
$pass = trim($pass);
|
||||
$email = trim($email);
|
||||
$pass = hashPassword($pass);
|
||||
|
||||
$result = mysqli_query($db,"Select uid from users where login='$login'");
|
||||
$row = mysqli_fetch_array($result);
|
||||
if (!empty($row['uid'])) {
|
||||
exit ("Извините, но данный логин уже занят.");
|
||||
}
|
||||
$result = mysqli_query($db,"Select uid from users where e_mail='$email'");
|
||||
$row = mysqli_fetch_array($result);
|
||||
if (!empty($row['uid'])) {
|
||||
exit ("Извините, но данная почта уже занята.");
|
||||
}
|
||||
$hash_code = rand(100000,999999);
|
||||
$subject = "Подтверждение регистрации";
|
||||
$message = "<p>Вы зарегистрировались на тестовом сервисе.</p>".
|
||||
"<p>Подтвердите регистрацию, перейдя по предложенной ".
|
||||
"<a href='http://dannc.doomstuff.com/activate.php?hash=" . $hash_code ."'>ссылке</a></p>";
|
||||
include ('smtp.php');
|
||||
if(!send_mime_mail($login,$email,$subject,$message,true)){
|
||||
echo "<b>Неверно указана электронная почта</b>. <a href='reg.php'>Вернуться к странице с регистрацией</a>";
|
||||
}
|
||||
else {
|
||||
$result2 = mysqli_query($db, "INSERT into users (login, pass, e_mail, ehash) values ('$login','$pass','$email','$hash_code')");
|
||||
if ($result2) {
|
||||
mysqli_commit($db);
|
||||
echo "Вы успешно зарегистрированы! На указанный e-mail отправлена ссылка для подтверждения регистрации.".
|
||||
"Теперь вы можете зайти на сайт. <a href='/index.php'>Главная страница</a>";
|
||||
}
|
||||
else {
|
||||
mysqli_rollback($db);
|
||||
echo "Ошибка! Вы не зарегистрированы. <a href='/reg.php>Назад</a>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
35
src/smtp.php
Executable file
35
src/smtp.php
Executable file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
function send_mime_mail($name_to, // имя получателя
|
||||
$email_to, // email получателя
|
||||
$subject, // тема письма
|
||||
$body, // текст письма
|
||||
$html = FALSE, // письмо в виде html или обычного текста
|
||||
$data_charset='utf-8', // кодировка переданных данных
|
||||
$send_charset='utf-8', // кодировка письма
|
||||
$reply_to = FALSE ) {
|
||||
$name_from = 'Test bot';
|
||||
$email_from = 'dan_nc@animeotaku.ru';
|
||||
$to = mime_header_encode($name_to, $data_charset, $send_charset)
|
||||
. ' <' . $email_to . '>';
|
||||
$subject = mime_header_encode($subject, $data_charset, $send_charset);
|
||||
$from = mime_header_encode($name_from, $data_charset, $send_charset)
|
||||
.' <' . $email_from . '>';
|
||||
if($data_charset != $send_charset) {
|
||||
$body = iconv($data_charset, $send_charset, $body);
|
||||
}
|
||||
$headers = "From: $from\r\n";
|
||||
$type = ($html) ? 'html' : 'plain';
|
||||
$headers .= "Content-type: text/$type; charset=$send_charset\r\n";
|
||||
$headers .= "Mime-Version: 1.0\r\n";
|
||||
if ($reply_to) {
|
||||
$headers .= "Reply-To: $reply_to";
|
||||
}
|
||||
return mail($to, $subject, $body, $headers);
|
||||
}
|
||||
function mime_header_encode($str, $data_charset, $send_charset) {
|
||||
if($data_charset != $send_charset) {
|
||||
$str = iconv($data_charset, $send_charset, $str);
|
||||
}
|
||||
return '=?' . $send_charset . '?B?' . base64_encode($str) . '?=';
|
||||
}
|
||||
?>
|
||||
49
src/trans.php
Executable file
49
src/trans.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
session_start();
|
||||
if (isset($_POST['uname'])){
|
||||
$name = $_POST['uname'];
|
||||
}
|
||||
$name = stripslashes($name);
|
||||
$name = htmlspecialchars($name);
|
||||
if (isset($_POST['sum'])){
|
||||
$sum = $_POST['sum'];
|
||||
if (!is_numeric($sum)){
|
||||
exit ("Нужно ввести число <a href='lk.php'>Вернуться назад</a>.");
|
||||
}
|
||||
}
|
||||
if (empty($name) or empty($sum)){
|
||||
exit("Нужно заполнить все поля. <a href='lk.php'>Вернуться назад</a>.");
|
||||
}
|
||||
if ($sum<0) { $sum=-$sum; }
|
||||
include("bdcon.php");
|
||||
mysqli_autocommit($db, false);
|
||||
|
||||
$res1 = mysqli_query($db,"Select * from users where login='$name'");
|
||||
if (!$res1){
|
||||
exit ("Пользователя с таким именем нет в базе. <a href='/lk.php'>Вернуться назад</a>");
|
||||
}
|
||||
$row1 = mysqli_fetch_array($res1);
|
||||
$uid1=$row1['uid'];
|
||||
|
||||
$uid2 = $_SESSION['id'];
|
||||
$res2 = mysqli_query($db, "Select * from users where uid=$uid2");
|
||||
$row2 = mysqli_fetch_array($res2);
|
||||
$name2 = $row2['login'];
|
||||
$sum2=-$sum;
|
||||
$comm2 = "Расход. Перевод пользователю $name.";
|
||||
|
||||
$dt = date("d-m-Y H:i");
|
||||
$comm1 = "Приход. Перевод от пользователя $name2.";
|
||||
|
||||
$qe1 = mysqli_query($db, "Insert into history (uid,tdate,`inout`,`comm`) values($uid1,STR_TO_DATE('$dt','%d-%m-%Y %H:%i'),$sum,'$comm1')");
|
||||
$qe2 = mysqli_query($db, "Insert into history (uid,tdate,`inout`,`comm`) values($uid2,STR_TO_DATE('$dt','%d-%m-%Y %H:%i'),$sum2,'$comm2')");
|
||||
|
||||
if ($qe1 and $qe2) {
|
||||
mysqli_commit($db);
|
||||
echo "Все прошло успешно. Вернуться в <a href='lk.php'>Личный кабинет</a>.";
|
||||
}
|
||||
else {
|
||||
mysqli_rollback($db);
|
||||
echo "Произошла ошибка.";
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user