Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. <?php
  2. $avatar;
  3. if ($_POST['name'] != null){
  4. $userName = $_POST['name'];
  5. }
  6. if ($_POST['city'] != null ) {
  7. $userCity = $_POST['city'];
  8. }
  9. if ($_POST['desc'] != null){
  10. $userDesc = $_POST['desc'];
  11. }
  12.  
  13. if ($_POST['login'] != '' && $_POST['pass'] != '' && $_POST['mail'] != '') {
  14.  
  15.  
  16. if (strlen($_POST['login']) > 3 && strlen($_POST['login']) < 10 && strlen($_POST['pass']) > 5 && strlen($_POST['pass']) < 16 ) {
  17. if (preg_match('/^[a-zA-Z0-9\.\-_]+\@[a-zA-Z0-9\.\-_]+\.[a-z]{2,4}$/D', $_POST['mail']) && preg_match('/^[a-zA-Z0-9\.\-_]/', $_POST['login']) ) {
  18.  
  19.  
  20. $userLogin = $_POST['login'];
  21. $userPass = $_POST['pass'];
  22. $userMail = $_POST['mail'];
  23. $len = 20;
  24.  
  25. echo $userID;
  26. if($_FILES['filename']['name'] != ''){
  27. $avatar = fileReceive();
  28. }
  29. reg();
  30. }
  31. else
  32. {
  33. header("Location: ../reg.php?reg=badchars");
  34. }
  35. }
  36. else
  37. {
  38. header("Location: ../reg.php?reg=shortpole");
  39. }
  40. }
  41. else
  42. {
  43. header("Location: ../reg.php?reg=emptyf");
  44. }
  45. function reg(){
  46. global $userID, $userMail, $userPass, $userLogin, $userDesc, $userCity, $userName, $avatar;
  47. try {
  48. $host = 'localhost';
  49. $baza = 'user';
  50. $uzytkownik = 'adamek';
  51. $haslo = 'aaaaa5';
  52.  
  53. $userID = checkID();
  54. $conn = new PDO("mysql:host=$host;dbname=$baza", $uzytkownik, $haslo);
  55. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  56. $stmt = $conn->prepare("SELECT Nazwa AND mail FROM Users WHERE Nazwa = '$userLogin' OR mail = '$userMail'");
  57. $stmt->execute();
  58. $row = $stmt->fetch();
  59.  
  60. if($row['Nazwa'] == 0 && $row['mail'] == 0 && $row['ID']){
  61. $stmt = $conn->exec("INSERT INTO Users ( ID , Nazwa , Haslo , mail , name , city , image , desci , activate , admin ) VALUES ('$userID','$userLogin', '$userPass', '$userMail', '$userName', '$userCity, $avatar', '$userDesc', 0 , 0 ");
  62.  
  63. echo "ok";
  64. #$sendMail();
  65. }
  66.  
  67. else{
  68. header("Location: ../reg.php?reg=userexists");
  69. }
  70. }
  71. catch(PDOException $e)
  72. {
  73. echo "duppppp";
  74. }
  75. }
  76.  
  77.  
  78.  
  79.  
  80. function fileReceive(){
  81. $max_size = 1024*1024;
  82. if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
  83. if ($_FILES['filename']['size'] > $max_size) {
  84. echo 'Błąd! Plik jest za duży!';
  85. }
  86. else {
  87. echo 'Odebrano plik. Początkowa nazwa: '.$_FILES['filename']['name'];
  88. echo '<br/>';
  89. if (isset($_FILES['filename']['type'])) {
  90. echo 'Typ: '.$_FILES['filename']['type'].'<br/>';
  91. }
  92. $strExt = substr( $_FILES['filename']['name'], strrpos( $_FILES['filename']['name'], '.' ) + 1 );
  93. echo "Rozszerzenie: ". $strExt;
  94. $len = 20;
  95. $randstring = substr(sha1(rand(1,10000)),0,$len).".jpg";
  96. echo $randstring;
  97. echo $_FILES['filename']['name'];
  98.  
  99. if ($strExt == 'jpg' || 'JPG' || 'jpeg' || 'JPEG'){
  100. move_uploaded_file($_FILES['filename']['tmp_name'],
  101. $_SERVER['DOCUMENT_ROOT'].'/avatars/'.$_FILES['filename']['name']);
  102.  
  103. }
  104. else{
  105. echo "niy!!";}
  106. }
  107. } else {
  108. echo 'Błąd przy przesyłaniu danych!';
  109. }
  110.  
  111. rename('../avatars/'.$_FILES['filename']['name'], "../avatars/". $randstring);
  112. return $randstring;
  113. }
  114.  
  115.  
  116.  
  117. function sendMail(){
  118. ob_start();
  119. $addressee = 'ajjambor912@gmail.com';
  120. @$email = $_POST['email'];
  121.  
  122. @$content = 'Name '.$_POST['username'].' Phone: '.$_POST['userphone'].' Content: '.$_POST['message'];
  123.  
  124. $header = "From: ".$_POST['email']." \nContent-Type:".
  125. ' text/plain;charset="iso-8859-2"'.
  126. "\nContent-Transfer-Encoding: 8bit";
  127. if (mail($addressee, 'Message from NAhandyman: ', $content , $header))
  128.  
  129. header('Location:index.php?send=true');
  130. else
  131. header('Location:index.php?send=false');
  132. }
  133.  
  134. function checkID(){
  135.  
  136.  
  137.  
  138. try {
  139. $host = 'localhost';
  140. $baza = 'user';
  141. $uzytkownik = 'adamek';
  142. $haslo = 'aaaaa5';
  143. $userID = substr(sha1(rand(1,10000)),0,$len);
  144.  
  145. $conn = new PDO("mysql:host=$host;dbname=$baza", $uzytkownik, $haslo);
  146. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  147. $stmt = $conn->prepare("SELECT ID FROM Users WHERE ID = '$userID'");
  148. $stmt->execute();
  149. $row = $stmt->fetch();
  150. $conn = null;
  151. if ($row['ID'] >= 1){
  152. checkID();
  153. }
  154. else{
  155. return $userID;
  156. }
  157. }
  158. catch(PDOException $e)
  159. {
  160. echo "duppeeeeek";
  161. }
  162.  
  163. }
  164.  
  165. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement