Created
February 9, 2016 23:33
-
-
Save anonymous/1bf41ff2c834833292ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
if(isset($_POST['email'])) | |
{ | |
//Udana walidacja? Załużmy że tak! | |
$wszystko_OK=true; | |
//Sprawdź poprawność nickname'a | |
$nick = $_POST['nick']; | |
//Sprawdzenie długości nicka | |
if((strlen($nick)<3) || (strlen($nick)>20)) | |
{ | |
$wszystko_OK=false; | |
$_SESSION['e_nick']="Nick musi posiadać od 3 do 20 znaków!"; | |
} | |
if(ctype_alnum($nick)==false) | |
{ | |
$wszystko_OK=false; | |
$_SESSION['e_nick']="Nick może składać się tylko z liter i cyfr (bez polskich znaków)."; | |
} | |
//Sprawdź poprawność adresu email | |
$email = $_POST['email']; | |
$emailB = filter_var($email, FILTER_SANITIZE_EMAIL); | |
if((filter_var($emailB, FILTER_VALIDATE_EMAIL)==false) || ($emailB!=$email)) | |
{ | |
$wszystko_OK=false; | |
$_SESSION['e_email']="Podaj poprawny adres e-mail!"; | |
} | |
//Sprawdź poprawność hasła | |
$haslo1 = $_POST['haslo1']; | |
$haslo2 = $_POST['haslo2']; | |
if((strlen($haslo1)<8) || (strlen($haslo1)>20)) | |
{ | |
$wszystko_OK=false; | |
$_SESSION['e_haslo']="Hasło musi posiadać od 8 do 20 znaków!"; | |
} | |
if($haslo1!=$haslo2) | |
{ | |
$wszystko_OK=false; | |
$_SESSION['e_haslo']="Podane hasła nie są identyczne!"; | |
} | |
// hashujemy hasło (password hash) | |
$haslo_hash = password_hash($haslo1, PASSWORD_DEFAULT); | |
//Czy zaakceptowano regulamin? | |
if(!isset($_POST['regulamin'])) | |
{ | |
$wszystko_OK=false; | |
$_SESSION['e_regulamin']="Potwierdź akteptację regulaminu!"; | |
} | |
//Bot or not? Oto jest pytanie! (reCaptcha) | |
$sekret = "6LcS3RcTAAAAAAMdddCc2spNTt8BtgSq2rzGJsnS"; | |
$sprawdz = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$sekret.'&response='.$_POST['g-recaptcha-response']); | |
$odpowiedz = json_decode($sprawdz); | |
if($odpowiedz->success==false) | |
{ | |
$wszystko_OK=false; | |
$_SESSION['e_bot']="Potwierdź że nie jesteś botem!"; | |
} | |
//Łączymy sie zbazą danych i sprawdzamy czy nie istnieje ktoś o takim samym loginie/email | |
require_once "connect.php"; | |
mysqli_report(MYSQLI_REPORT_STRICT); | |
try | |
{ | |
$polaczenie = new mysqli($host, $db_user, $db_password, $db_name); | |
if($polaczenie->connect_errno!=0) | |
{ | |
throw new Exception(mysqli_connect_errno()); | |
} | |
else | |
{ | |
//Czy email juz istnieje? | |
$rezultat = $polaczenie->query("SELECT id FROM uzytkownicy WHERE email='$email'"); | |
if(!$rezultat) throw new Exception($polaczenie->error); | |
$ile_takich_maili = $rezultat->num_rows; | |
if($ile_takich_maili>0) | |
{ | |
$wszystko_OK=false; | |
$_SESSION['e_email']="Istnieje już konto o takim samym adresie e-mail!"; | |
} | |
//Czy nick jest już zarezerwowany? | |
$rezultat = $polaczenie->query("SELECT id FROM uzytkownicy WHERE user='$nick'"); | |
if(!$rezultat) throw new Exception($polaczenie->error); | |
$ile_takich_nickow = $rezultat->num_rows; | |
if($ile_takich_nickow>0) | |
{ | |
$wszystko_OK=false; | |
$_SESSION['e_nick']="Istnieje już konto o takim nicku!"; | |
} | |
// OK OK OK OK | |
if($wszystko_OK==true) | |
{ | |
//Hurra, wszystkie testy zaliczone, dodajemy gracza do bazy | |
if ($polaczenie->query("INSERT INTO uzytkownicy VALUES (NULL, '$nick', '$haslo_hash', '$email', 0, 0)")) | |
{ | |
$_SESSION['udanarejestracja']=true; | |
header('Location: witamy.php'); | |
} | |
else | |
{ | |
throw new Exception($polaczenie->error); | |
} | |
} | |
$polaczenie->close(); | |
} | |
} | |
catch(Exception $e) | |
{ | |
echo '<br /><br /><span style="color:red;">Błąd serwera! Przepraszamy za niedogodniści i prosimy o rejestrację w innym terminie!</span>'; | |
//echo '<br />Informacja developerska: '.$e; | |
} | |
} | |
?> | |
<!DOCTYPE HTML> | |
<!-- | |
Spectral by HTML5 UP | |
html5up.net | @n33co | |
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license) | |
--> | |
<html> | |
<head> | |
<title>SKGO - CS:GO Skins Shop</title> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<!--[if lte IE 8]><script src="assets/js/ie/html5shiv.js"></script><![endif]--> | |
<link rel="stylesheet" href="assets/css/main.css" /> | |
<!--[if lte IE 8]><link rel="stylesheet" href="assets/css/ie8.css" /><![endif]--> | |
<script src='https://www.google.com/recaptcha/api.js'></script> | |
<!--[if lte IE 9]><link rel="stylesheet" href="assets/css/ie9.css" /><![endif]--> | |
</head> | |
<body> | |
<!-- Page Wrapper --> | |
<div id="page-wrapper"> | |
<!-- Header --> | |
<header id="header"> | |
<h1><a href="index.html">SKGO - CS:GO Skins Shop</a></h1> | |
<nav id="nav"> | |
<ul> | |
<li class="special"> | |
<a href="#menu" class="menuToggle"><span>Menu</span></a> | |
<div id="menu"> | |
<ul> | |
<li><a href="index.php">Home</a></li> | |
<li><a href="login.php">Zaloguj się</a></li> | |
<li><a href="rejestracja.php">Zarejestruj się</a></li> | |
</ul> | |
</div> | |
</li> | |
</ul> | |
</nav> | |
</header> | |
<!-- Main --> | |
<article id="main"> | |
<header> | |
<h2>Rejestracja</h2> | |
</header> | |
<section class="wrapper style5"> | |
<div class="inner"> | |
<center><h3>Panel Rejestracji</h3></center> | |
<form method="post"> | |
<input type="text" name="nick" placeholder="Nickname" /> | |
<?php | |
if(isset($_SESSION['e_nick'])) | |
{ | |
echo '<div class="error">'.$_SESSION['e_nick'].'</div>'; | |
unset($_SESSION['e_nick']); | |
} | |
?> | |
<br /> | |
<input type="text" name="email" placeholder="E-mail" /> | |
<?php | |
if(isset($_SESSION['e_email'])) | |
{ | |
echo '<div class="error">'.$_SESSION['e_email'].'</div>'; | |
unset($_SESSION['e_email']); | |
} | |
?> | |
<br /> | |
<input type="password" name="haslo1" placeholder="Hasło" /> | |
<?php | |
if(isset($_SESSION['e_haslo'])) | |
{ | |
echo '<div class="error">'.$_SESSION['e_haslo'].'</div>'; | |
unset($_SESSION['e_haslo']); | |
} | |
?> | |
<br /> | |
<input type="password" name="haslo2" placeholder="Powtórz hasło" /> | |
<br /> | |
<input type="text" name="tradelink" placeholder="Steam Trade URL" /> | |
<br /> | |
<label> | |
<center><input type="checkbox" name="regulamin" class="wrapper style1" /> Akceptuję regulamin</center> | |
</label> | |
<center> | |
<?php | |
if(isset($_SESSION['e_regulamin'])) | |
{ | |
echo '<div class="error">'.$_SESSION['e_regulamin'].'</div>'; | |
unset($_SESSION['e_regulamin']); | |
} | |
?> | |
</center> | |
<center> | |
<div class="g-recaptcha" data-sitekey="6LcS3RcTAAAAAL_RyjLxRZivWh-U5AFoh1HlyYs3"></div> | |
<?php | |
if(isset($_SESSION['e_bot'])) | |
{ | |
echo '<div class="error">'.$_SESSION['e_bot'].'</div>'; | |
unset($_SESSION['e_bot']); | |
} | |
?> | |
<br /> | |
<input type="submit" value="Zarejestruj się" class="button special small" /></center> | |
</form> | |
<!--<form action="zaloguj.php" method="post"> | |
<center> | |
<input type="text" name="login" placeholder="Login" /> | |
<br /> | |
<input type="password" name="haslo" placeholder="Password" /> | |
<br /> | |
<input type="submit" value="Zaloguj się" class="button special small" /> | |
</center> | |
</form>--> | |
</div> | |
</section> | |
</article> | |
<!-- Footer --> | |
<footer id="footer"> | |
<ul class="icons"> | |
<li><a href="#" class="icon fa-twitter"><span class="label">Twitter</span></a></li> | |
<li><a href="#" class="icon fa-facebook"><span class="label">Facebook</span></a></li> | |
<li><a href="#" class="icon fa-instagram"><span class="label">Instagram</span></a></li> | |
<li><a href="#" class="icon fa-dribbble"><span class="label">Dribbble</span></a></li> | |
<li><a href="#" class="icon fa-envelope-o"><span class="label">Email</span></a></li> | |
</ul> | |
<ul class="copyright"> | |
<li>© 2016 / 2017</li><li>Design: <a href="index.html">skgo.prv.pl</a></li> | |
</ul> | |
</footer> | |
</div> | |
<!-- Scripts --> | |
<script src="assets/js/jquery.min.js"></script> | |
<script src="assets/js/jquery.scrollex.min.js"></script> | |
<script src="assets/js/jquery.scrolly.min.js"></script> | |
<script src="assets/js/skel.min.js"></script> | |
<script src="assets/js/util.js"></script> | |
<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]--> | |
<script src="assets/js/main.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment