| AND OR | string words | *

sessions and co

|

basic authorization


basic authorization script to protect pages like administration, upload etc. put this code at the beginning of the page you want to protect.



full source of basic authorization [ line 1 - 33 ] | download basic authorization

1    <?php
2   // the name of the section you want to protect
3   $site_section 'phparadise admin section';
4   // the desired username / password
5   $user 'admin';
6   $password 'tester';
7   // check if not authorized already
8   if(!isset($_SERVER['PHP_AUTH_USER']))
9   {
10       // if not authorized, show authentication dialog box
11       header('WWW-Authenticate: Basic realm="'.$site_section.'"');
12       header('HTTP/1.0 401 Unauthorized');
13       echo 'Authorization Required.';
14       exit;
15   }else{
16       // if user or password is wrong
17       if(($_SERVER['PHP_AUTH_USER'] != $user) || ($_SERVER['PHP_AUTH_PW'] != $password))
18       {
19           // show authentication dialog box again
20           header('WWW-Authenticate: Basic realm="'.$site_section.'"');
21           header('HTTP/1.0 401 Unauthorized');
22           echo 'Authorization Required.';
23           exit;
24       }else{
25           // if user and password match
26           echo '
27           <h1>welcome '.$user.'!</h1>
28           you now have access to '.$site_section;
29       }
30   }
31   // set session or cookie to keep authorization for other pages
32   // put your page content here
33   ?>



13 hits by 8 users in the last 30 minutes.