Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Jonas J. http://www.jonasjohn.de/

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

WWW-Authenticate example

// Shows how to use the WWW-Authenticate header to make login pages.You find a good tutorial at php.net
// (Source: http://codedump.jonasjohn.de/ - Public domain)

   1  
   2  <?php
   3  
   4  $login_successful = false;
   5  
   6  // check user & pwd:
   7  if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){
   8  
   9      $usr = $_SERVER['PHP_AUTH_USER'];
  10      $pwd = $_SERVER['PHP_AUTH_PW'];
  11  
  12      if ($usr == 'jonas' && $pwd == 'secret'){
  13          $login_successful = true;
  14      }
  15  }
  16  
  17  // login ok?
  18  if (!$login_successful){
  19  
  20      // send 401 headers:
  21      // realm="something" will be shown in the login box 
  22      header('WWW-Authenticate: Basic realm="Secret page"');
  23      header('HTTP/1.0 401 Unauthorized');
  24      print "Login failed!\n";
  25  
  26  }
  27  else {
  28      // show secret page:
  29      print 'you reached the secret page!';
  30  }
  31  ?>
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS