Advertisement
Guest User

Untitled

a guest
Apr 12th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $errors = array();
  4. if (count($errors) > 0) : ?>
  5. <div class="error">
  6. <?php foreach ($errors as $error) : ?>
  7. <p><?php echo $error ?></p>
  8. <?php endforeach ?>
  9. </div>
  10. <?php endif;
  11. if (isset($_POST['reg'])) {
  12. $username = $_POST['username'];
  13. $email = $_POST['mail'];
  14. $password = $_POST['password'];
  15. $password2 = $_POST['password2'];
  16. if ($password != $password2) {
  17. echo "Passwords do not match";
  18. }
  19. $data = file_get_contents('users.json');
  20. $character = json_decode($data, true);
  21. echo '<pre>PRINT ARRAY: ' . print_r($character, true) . '</pre>';
  22. echo json_last_error();
  23. if (isset($_POST['reg'])) {
  24. $map = "uploads/";
  25. $image = $map . basename($_FILES["pic"]["name"]);
  26. $continue = 1;
  27. $imageFileType = strtolower(pathinfo($image, PATHINFO_EXTENSION));
  28. // Check if image file is a actual image or fake image
  29. if (isset($_POST["pic"])) {
  30. $check = getimagesize($_FILES["pic"]["tmp_name"]);
  31. if ($check !== false) {
  32. echo "File is an image - " . $check["mime"] . ".";
  33. $continue = 1;
  34. } else {
  35. echo "File is not an image.";
  36. $continue = 0;
  37. }
  38. }
  39. if ($_FILES["pic"]["size"] > 5000000) {
  40. echo "Sorry, your file is too large.";
  41. $continue = 0;
  42. } else {
  43. $file = fopen("users.json", "a");
  44. }
  45. if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
  46. && $imageFileType != "gif") {
  47. echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  48. $continue = 0;
  49. } else {
  50. $file = fopen("users.json", "a");
  51. }
  52. if ($continue == 0) {
  53. echo "Sorry, your file was not uploaded.";
  54. } else {
  55. if (move_uploaded_file($_FILES["pic"]["tmp_name"], $image)) {
  56. echo "<p class='filesaved'>The file " . basename($_FILES["pic"]["name"]) . " has been uploaded.<br></p>";
  57. $file = fopen("users.json", "a");
  58. } else {
  59. echo "Sorry, there was an error uploading your file.";
  60. }
  61. }
  62.  
  63. if (!$file) {
  64. echo "Cant find the file";
  65. }
  66. if (isset($_POST['username']) && isset($_POST['mail']) && isset($_POST['password'])) {
  67. $user = htmlspecialchars($_POST['username']);
  68. $mail = htmlspecialchars($_POST['mail']);
  69. $password = htmlspecialchars($_POST['password']);
  70. $avatar = $image;
  71. $_SESSION["username"] = $user;
  72. $_SESSION["mail"] = $mail;
  73. $username = $_SESSION["username"];
  74. $data = $user . PHP_EOL . $mail . PHP_EOL . $password . PHP_EOL . $avatar . PHP_EOL . PHP_EOL;
  75.  
  76. $myArr = array($user, $email, $password, $avatar);
  77. $myJSON = json_encode($myArr, JSON_FORCE_OBJECT);
  78. fwrite($file, $myJSON);
  79. fclose($file);
  80. echo "<!DOCTYPE html>
  81. <html lang=\"en\">
  82. <head>
  83. <meta charset=\"UTF-8\">
  84. <title>Succes</title>
  85. <link rel=\"stylesheet\" href=\"styles.css\">
  86. </head>
  87. <body>
  88. <p class=\"succestext\">Succes</p>
  89. <script>
  90. window.setTimeout(
  91. function(){
  92. window.location.href = \"home.php\";
  93. }, 10000);
  94. </script>
  95. </body>
  96. </html>";
  97. }
  98. }
  99. }
  100. if (isset($_POST['login'])) {
  101. $username = $_POST['username'];
  102. $password = $_POST['password'];
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement