Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $errors = array();
- if (count($errors) > 0) : ?>
- <div class="error">
- <?php foreach ($errors as $error) : ?>
- <p><?php echo $error ?></p>
- <?php endforeach ?>
- </div>
- <?php endif;
- if (isset($_POST['reg'])) {
- $username = $_POST['username'];
- $email = $_POST['mail'];
- $password = $_POST['password'];
- $password2 = $_POST['password2'];
- if ($password != $password2) {
- echo "Passwords do not match";
- }
- $data = file_get_contents('users.json');
- $character = json_decode($data, true);
- echo '<pre>PRINT ARRAY: ' . print_r($character, true) . '</pre>';
- echo json_last_error();
- if (isset($_POST['reg'])) {
- $map = "uploads/";
- $image = $map . basename($_FILES["pic"]["name"]);
- $continue = 1;
- $imageFileType = strtolower(pathinfo($image, PATHINFO_EXTENSION));
- // Check if image file is a actual image or fake image
- if (isset($_POST["pic"])) {
- $check = getimagesize($_FILES["pic"]["tmp_name"]);
- if ($check !== false) {
- echo "File is an image - " . $check["mime"] . ".";
- $continue = 1;
- } else {
- echo "File is not an image.";
- $continue = 0;
- }
- }
- if ($_FILES["pic"]["size"] > 5000000) {
- echo "Sorry, your file is too large.";
- $continue = 0;
- } else {
- $file = fopen("users.json", "a");
- }
- if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
- && $imageFileType != "gif") {
- echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
- $continue = 0;
- } else {
- $file = fopen("users.json", "a");
- }
- if ($continue == 0) {
- echo "Sorry, your file was not uploaded.";
- } else {
- if (move_uploaded_file($_FILES["pic"]["tmp_name"], $image)) {
- echo "<p class='filesaved'>The file " . basename($_FILES["pic"]["name"]) . " has been uploaded.<br></p>";
- $file = fopen("users.json", "a");
- } else {
- echo "Sorry, there was an error uploading your file.";
- }
- }
- if (!$file) {
- echo "Cant find the file";
- }
- if (isset($_POST['username']) && isset($_POST['mail']) && isset($_POST['password'])) {
- $user = htmlspecialchars($_POST['username']);
- $mail = htmlspecialchars($_POST['mail']);
- $password = htmlspecialchars($_POST['password']);
- $avatar = $image;
- $_SESSION["username"] = $user;
- $_SESSION["mail"] = $mail;
- $username = $_SESSION["username"];
- $data = $user . PHP_EOL . $mail . PHP_EOL . $password . PHP_EOL . $avatar . PHP_EOL . PHP_EOL;
- $myArr = array($user, $email, $password, $avatar);
- $myJSON = json_encode($myArr, JSON_FORCE_OBJECT);
- fwrite($file, $myJSON);
- fclose($file);
- echo "<!DOCTYPE html>
- <html lang=\"en\">
- <head>
- <meta charset=\"UTF-8\">
- <title>Succes</title>
- <link rel=\"stylesheet\" href=\"styles.css\">
- </head>
- <body>
- <p class=\"succestext\">Succes</p>
- <script>
- window.setTimeout(
- function(){
- window.location.href = \"home.php\";
- }, 10000);
- </script>
- </body>
- </html>";
- }
- }
- }
- if (isset($_POST['login'])) {
- $username = $_POST['username'];
- $password = $_POST['password'];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement