Skip to content

Instantly share code, notes, and snippets.

@songwutk
Created February 12, 2022 07:24
Show Gist options
  • Save songwutk/c4ce3a4ffd3f6e12f9dfba5a0e77b7ae to your computer and use it in GitHub Desktop.
Save songwutk/c4ce3a4ffd3f6e12f9dfba5a0e77b7ae to your computer and use it in GitHub Desktop.
PHP header authentication
<?php
// POSTMAN Authorization
// Basic Auth
// Fill => Username & Password
$username="api-user";
$password="ajck_[99HkJC";
// phpinfo();
// print_r($_SERVER);
if ($_SERVER["PHP_AUTH_USER"]==$username && $_SERVER["PHP_AUTH_PW"]==$password)
{
header('Content-Type: application/json; charset=utf-8');
echo json_encode(["data"=>"Welcome"]);
}
else
{
header('HTTP/1.0 403 Forbidden');
echo json_encode(["data"=>"Access denied"]);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment