Odrazu piszę czemu tak namieszane w kodzie: jak chciałem pobrać dane z tablicy $data to skrypt wogóle nie działał.
Kod php:
<?php $textMessages = [ 0 => 'Uzupełnij wszystkie pola formularza', 1 => 'Wpisz poprawny adres E-mail.', 2 => 'Wpisz poprawne dane.', 3 => 'Za chwilę zostaniesz przekierowany.', 4 => 'Nie wysłano formularza.', 5 => 'Złe hasło' ]; $data['password'] = hash('sha256', $data['password']); dbcon("xxx","xxx","xxx","xxx"); $haslo = $_POST['haslo']; $hash = hash('sha256', $haslo); $zaphash = "SELECT id FROM users WHERE haslo = '".mysql_real_escape_string($hash)."'and email='".mysql_real_escape_string($_POST['email'])."'"; { $array = [false, $textMessages[0]]; } elseif (!filter_var($data['email'], FILTER_VALIDATE_EMAIL)) { $array = [false, $textMessages[1]]; } $array = [false, $textMessages[1]]; } $array = [false, $textMessages[5]]; } else { $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; $_SESSION['email'] = $data['email']; $_SESSION['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $array = [true, $textMessages[3]]; } } else { $array = [false, $textMessages[4]]; } ?>
Plik JS
// JavaScript Document function redirect(to, delay) { window.setTimeout(function () { window.location.href = to; }, delay); } $('.form').before('<div id="info"></div>'); $('.form').on('submit', function (e) { var email = $("#email").val() ,password = $("#password").val() ,string = '&email=' + email + '&password=' + password + '&action=login'; var request = $.ajax( { url: "checker.php", type: "POST", datatype: "json", data: string }); request.done(function (html) { redirect('my_page.php', 1000); } } }); e.preventDefault(); });