Advertisement
Guest User

Untitled

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