Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. <?php
  2. class Core {
  3.  
  4. var $Host = 'localhost';
  5. var $User = 'root';
  6. var $Pass = 'siklo94';
  7. var $Db = 'mcmgame';
  8.  
  9.  
  10. function Core() {
  11.  
  12. $Link = mysql_connect($this->Host, $this->User, $this->Pass);
  13.  
  14. if ( !$Link ) {
  15.  
  16. die( mysql_error() );
  17. }
  18.  
  19. if ( !mysql_select_db($this->Db) ) {
  20.  
  21. die( mysql_error() );
  22. }
  23. }
  24.  
  25. function Query($Sql) {
  26.  
  27. $Query = mysql_query( $Sql );
  28.  
  29. if ( !$Query ) {
  30.  
  31. return false;
  32. }
  33.  
  34. return $Query;
  35. }
  36.  
  37. function QueryArray($Sql) {
  38.  
  39. $Result = array();
  40. $Counter = 0;
  41.  
  42. $Query = $this->Query( $Sql );
  43.  
  44. if ( $Query == false ) {
  45.  
  46. return false;
  47. }
  48.  
  49. while ( $Row = mysql_fetch_array($Query) ) {
  50.  
  51. foreach ( $Row as $Key => $Value ) {
  52.  
  53. $Result[$Counter][$Key] = $Value;
  54. }
  55.  
  56. $Counter++;
  57. }
  58.  
  59. return $Result;
  60. }
  61.  
  62. function QueryNum( $Sql ) {
  63.  
  64. $Query = $this->Query( $Sql );
  65.  
  66. return mysql_num_rows( $Query );
  67. }
  68.  
  69. function GetKey() {
  70.  
  71. $Chars='0123456789qwertzuioplkjhgfdsayxcvbnm';
  72. $Key='';
  73.  
  74. for ( $i=0; $i<10; $i++ ) {
  75.  
  76. $Key.=$Chars[rand(0,strlen($Chars)-1)];
  77. }
  78.  
  79. return $Key;
  80. }
  81.  
  82. //Regisztráció
  83. function Reg(){
  84.  
  85. //htmlspecialchars függvénnyel kiszedjük a nem oda illő karaktereket
  86. $Name = htmlspecialchars($_POST['Name']);
  87. $Mail = htmlspecialchars($_POST['Mail']);
  88. $Pwd = htmlspecialchars($_POST['Pwd']);
  89. $RePwd = htmlspecialchars($_POST['RePwd']);
  90.  
  91. //Megvizsgáljuk nincs e üres mező
  92. if ( empty($Name) OR empty($Mail) OR empty($Pwd) OR empty($RePwd) ) {
  93.  
  94. return 'Az összes mező kiteöltése kötelező!';
  95.  
  96. }
  97.  
  98. //Megvizsgáljuk regisztráltak e már a beírt névvel
  99. if ( $this->QueryNum("SELECT id FROM users WHERE name='".$Name."'") > 0 ) {
  100.  
  101. return 'Ez a felhasználónév már foglalt!';
  102.  
  103. }
  104.  
  105. //Megvizsgáljuk regisztráltak e már a beírt e-mail címmel
  106. if ( $this->QueryNum("SELECT id FROM users WHERE mail='".$Mail."'") > 0 ) {
  107.  
  108. return 'Ezzel az e-mail címmel már regisztráltak!';
  109.  
  110. }
  111.  
  112. //Megvizsgáljuk a két jelszó egyezését
  113. if ( $Pwd != $RePwd ) {
  114.  
  115. return 'A két jelszó nem egyezik!';
  116.  
  117. }
  118.  
  119. //Ha nincs üres mező feltöltjük az adatokat az user táblába
  120. if( !empty($_POST) ) {
  121.  
  122. $this->Query("INSERT INTO users (name,pwd,mail) VALUES ('".$Name."','".md5($Pwd)."','".$Mail."')");
  123.  
  124. return 'Sikeres regisztráció!';
  125.  
  126. }else{
  127.  
  128. return 'A regisztráció során hiba lépett fel!';
  129.  
  130. }
  131. }
  132.  
  133. //Bejelentkezés
  134. function Login() {
  135.  
  136. $Name = htmlspecialchars($_POST['Name']);
  137. $Pwd = htmlspecialchars($_POST['Pwd']);
  138.  
  139. //Megvizsgáljuk nincs e üres mező
  140. if ( empty($Name) OR empty($Pwd) ) {
  141.  
  142. return 'Az összes mező kiteöltése kötelező!';
  143.  
  144. }
  145.  
  146. //Megvizsgáljuk adatbázisban a beírt adatokat
  147. $Sql = "SELECT id FROM users WHERE name='".$Name."' AND pwd='".md5($Pwd)."'";
  148.  
  149. //Ha a beírt adatok helytelenek hibaüzenet
  150. if ( $this->QueryNum( $Sql ) == 0 ) {
  151.  
  152. return 'Hibás felhazsnálónév és/vagy jelszó!';
  153.  
  154. //Sikeres belépés esetén süti létrehozása és átirányítás
  155. }else{
  156.  
  157. header("Location: main.php");
  158.  
  159. }
  160. }
  161. }
  162. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement