Apache/PHP HTTP Authentication

Aside from having a complex login page where you can prevent access to users without privileges ,  PHP offers a simple way to do it.

But you must have an Apache Server (most of the servers are Apache).

Here is the code:

  1. if ($_SERVER[‘PHP_AUTH_USER’] != ‘admin’ and $_SERVER[‘PHP_AUTH_PW’] != ‘admin’) {
  2.  header(‘WWW-Authenticate: Basic realm="TCG Admin Panel"’);
  3.  header(‘HTTP/1.0 401 Unauthorized’);
  4.  echo ‘You need to login’;
  5.  exit;
  6. } else {
  7. echo "OK!";
  8. }

Learn more about it here

Leave a Reply