Created
May 28, 2017 13:00
-
-
Save vporoshok/0c4b0620324b04cf50b21fcd1d95b101 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| session_start(); | |
| if ($_SERVER['REQUEST_METHOD'] === 'POST') { | |
| $dataRaw = file_get_contents('php://input'); | |
| $data = json_decode($dataRaw, true); | |
| var_dump($data); | |
| $_SESSION['email'] = $data['email']; | |
| header('Location: /form.php'); | |
| exit(); | |
| } | |
| ?> | |
| <form name="login"> | |
| <input name="email"> | |
| <button>Login</button> | |
| </form> | |
| <script> | |
| var form = document.forms.namedItem('login'); | |
| form.addEventListener('submit', e => { | |
| e.preventDefault(); | |
| var email = form.querySelector('input[name="email"]'); | |
| var data = { | |
| email: email.value | |
| }; | |
| var req = new XMLHttpRequest(); | |
| req.open('POST', '/login.php'); | |
| req.setRequestHeader('Content-Type', 'application/json'); | |
| req.addEventListener('readystatechange', e => { | |
| if (req.readyState !== req.DONE) { | |
| return; | |
| } | |
| if (req.status === 200) { | |
| window.location = '/form.php'; | |
| } | |
| }); | |
| req.send(JSON.stringify(data)); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment