Advertisement
Guest User

Untitled

a guest
May 7th, 2016
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  1. $stmt = $DB_con->prepare("SELECT user_name,user_email FROM users WHERE user_name=:uname OR user_email=:umail");
  2.  
  3. <?php
  4.  
  5. session_start();
  6.  
  7. $DB_host = "localhost";
  8. $DB_name = "dbeva";
  9. $DB_user = "root";
  10. $DB_pass = "";
  11.  
  12. try {
  13.  
  14. $DB_con = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass);
  15. $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  16. echo "<div class='bildirim'>- Veritabanına Bağlandı !</div>";
  17.  
  18. }
  19.  
  20. catch(PDOException $e) {
  21.  
  22. echo $e->getMessage();
  23. echo "<div class='bildirim'>- Veritabanı Bağlantısı Başarısız !</div>";
  24.  
  25. }
  26.  
  27. include_once 'userclass.php';
  28. $user = new user($DB_con);
  29.  
  30. ?>
  31.  
  32. <?php
  33.  
  34. class user {
  35.  
  36. private $db;
  37.  
  38. function __construct($DB_con) {
  39.  
  40. $this->db = $DB_con;
  41. echo "<div class='bildirim'>- Constructor Çalıştı !</div>";
  42.  
  43. } // Constructor Function
  44.  
  45. public function check($cuname,$cumail,$cupass) {
  46.  
  47. if ($cuname == "") {
  48.  
  49. echo "<div class='bildirim'>Kullanıcı adı boş bırakılamaz.</div>";
  50.  
  51. } // if $cuname == ""
  52.  
  53. else if (strlen($cuname) < 6 && strlen($cuname) > 15) {
  54.  
  55. echo "<div class='bildirim'>Kullanıcı adı 6 ile 15 karakter arasında olmalıdır.</div>";
  56.  
  57. } // else if 6 <= $cuname <= 15
  58.  
  59. else if ($cumail == "") {
  60.  
  61. echo "<div class='bildirim'>Email boş bırakılamaz.</div>";
  62.  
  63. } // else if $cumail == ""
  64.  
  65. else if (!filter_var($cumail, FILTER_VALIDATE_EMAIL)) {
  66.  
  67. echo "<div class='bildirim'>Lütfen geçerli bir mail adresi girin.</div>";
  68.  
  69. } // else if validate email
  70.  
  71. else if ($cupass == "") {
  72.  
  73. echo "<div class='bildirim'>Şifre boş bırakılamaz.</div>";
  74.  
  75. } //else if $cupass == ""
  76.  
  77. else if (strlen($cupass) < 6) {
  78.  
  79. echo "<div class='bildirim'>Şifre en az 6 karakter olmalıdır.</div>";
  80.  
  81. } // else if $upass < 6
  82.  
  83. else {
  84.  
  85. try {
  86.  
  87. $stmt = $DB_con->prepare("SELECT user_name,user_email FROM users WHERE user_name=:uname OR user_email=:umail");
  88. $stmt->execute(array(':uname'=>$cuname, ':umail'=>$cumail));
  89. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  90.  
  91. if($row['user_name'] == $cuname) {
  92.  
  93. echo "<div class='bildirim'>Üzgünüz, kullanıcı adı çoktan alınmış.</div>";
  94.  
  95. } // if user_name exist
  96.  
  97. else if($row['user_email'] == $cumail) {
  98.  
  99. echo "<div class='bildirim'>Üzgünüz, sitemizde bu mail adresi ile kayıtlı bir üye zaten var.</div>";
  100.  
  101. } // else if user_email exist
  102.  
  103. else {
  104.  
  105. try {
  106.  
  107. $new_pass = password_hash($cupass, PASSWORD_DEFAULT);
  108.  
  109. $stmt = $this->db->prepare("INSERT INTO users(user_name,user_email,user_pass)
  110. VALUES(:uname,:umail,:upass)");
  111.  
  112. $stmt->bindparam(":uname", $cuname);
  113. $stmt->bindparam(":umail", $cumail);
  114. $stmt->bindparam(":upass", $new_pass);
  115. $stmt->execute();
  116. return $stmt;
  117.  
  118. echo "<div class='bildirim'>- Kayıt İşlemi Başarılı !</div>";
  119.  
  120. } // try register
  121.  
  122. catch(PDOException $e) {
  123.  
  124. echo $e->getMessage();
  125. echo "<div class='bildirim'>- Kayıt İşlemi Başarısız !</div>";
  126.  
  127. } // catch register
  128.  
  129. } // else
  130.  
  131. } // try check
  132.  
  133. catch (PDOException $e) {
  134.  
  135. echo $e->getMessage();
  136.  
  137. } // catch check
  138.  
  139. } // else
  140.  
  141. } // Function Check
  142.  
  143. } // User Class
  144.  
  145. ?>
  146.  
  147. <?php
  148.  
  149. require_once "dbconfig.php";
  150.  
  151. if (isset($_POST['btn_signup'])) {
  152.  
  153. $r_uname = trim($_POST['r_uname']);
  154. $r_uname = strip_tags($r_uname);
  155. $r_umail = trim($_POST['r_umail']);
  156. $r_umail = strip_tags($r_umail);
  157. $r_upass = trim($_POST['r_upass']);
  158. $r_upass = strip_tags($r_upass);
  159.  
  160. $user->check($r_uname,$r_umail,$r_upass);
  161.  
  162. } // if isset btn_signup
  163.  
  164. if (isset($_POST['btn_login'])) {
  165.  
  166. //$user->login();
  167.  
  168. } // if isset btn_signup
  169.  
  170. ?>
  171.  
  172. <html>
  173. <head>
  174. <head>
  175. <title>Eva Login System</title>
  176. <meta charset="UTF-8">
  177. <link rel="stylesheet" type="text/css" href="style.css"/>
  178. <link href='https://fonts.googleapis.com/css?family=Open+Sans:' rel='stylesheet' type='text/css'>
  179. </head>
  180. </head>
  181. <body>
  182. <div class="formwrapper">
  183. <h2>Giriş Yap !</h2>
  184. <form method="post" action="">
  185. <input class="inputa" type="text" name="l_umail" placeholder="Email">
  186. <input class="inputa" type="password" name="l_upass" placeholder="Şifre">
  187. <input class="inputb" type="submit" name="btn_login" value="Giriş Yap">
  188. </form>
  189. </div>
  190. <div class="formwrapper">
  191. <h2>Bize Katıl !</h2>
  192. <form method="post" action="">
  193. <input class="inputa" type="text" name="r_uname" placeholder="Kullanıcı Adı">
  194. <input class="inputa" type="text" name="r_umail" placeholder="Email">
  195. <input class="inputa" type="text" name="r_upass" placeholder="Şifre">
  196. <input class="inputb" type="submit" name="btn_signup" value="Hesap Aç">
  197. </form>
  198. </div>
  199. </body>
  200. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement