Skip to content

Instantly share code, notes, and snippets.

@marijnvdwerf
Created June 9, 2013 15:47
Show Gist options
  • Save marijnvdwerf/5744002 to your computer and use it in GitHub Desktop.
Save marijnvdwerf/5744002 to your computer and use it in GitHub Desktop.
Simple login
<?php
if($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405); // Method Not Allowed
echo 'Data should be POST\'ed';
die();
}
if(!isset($_POST['username'])) {
http_response_code(400); // Bad Request
echo 'Username not specified';
die();
}
if(!isset($_POST['password'])) {
http_response_code(400); // Bad Request
echo 'Password not specified';
die();
}
if($_POST['username'] === 'aap' && $_POST['password'] === 'aap') {
http_response_code(200); // OK
echo 'Success!';
die();
}
http_response_code(401); // Unauthorized
echo 'Invalid username or password';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment