|
Posted by Chris on 07/29/05 16:46
Thanks Rob - appreciate your help VERY much. :-)
Chris
On Thu, 28 Jul 2005 16:28:58 +0000 (UTC), Rob
<rob.@.no.spam.please.tbswebdesign.com> wrote:
>> Chris... iv come up with this for you...
>> This example will give access dependant on the username and password
>> entered.
>> You can added/delete users from the $users array.
>>
>> -----------
>>
>> function do_auth()
>> {
>> $realm = mt_rand(1,1000);
>> header('WWW-Authenticate: Basic realm="CMMS Administation ID:
>> '.$realm.'"');
>> header('HTTP/1.0 401 Unauthorized');
>> die("Permission Denied");
>> }
>> //your access info... user => pass
>> $users = array('admin' => 'admin', 'staff' => 'staff');
>>
>> if (!isset($_SERVER['PHP_AUTH_USER']))
>> {
>> do_auth();
>> }
>> elseif (!isset($_SERVER['PHP_AUTH_PW']))
>> {
>> do_auth();
>> }
>> elseif($users[$_SERVER['PHP_AUTH_USER']] != $_SERVER['PHP_AUTH_PW'])
>> {
>> do_auth();
>> }
>> //if were here... then were logged in successfully :)
>> print('Welcome to the control panel
>> <b>'.$_SERVER['PHP_AUTH_USER'].'</b>');
>>
>> -----------
>>
>>
>> This second example give access to ips listed the array $allowed_ips
>> hopefully one of these may be of help to you...
>> but http auth is not the best method of passwording, all depends on how
>> secure you want the protected content to be.
>>
>>
>> ---------
>>
>> function do_auth()
>> {
>> $realm = mt_rand(1,1000);
>> header('WWW-Authenticate: Basic realm="CMMS Administation ID:
>> '.$realm.'"');
>> header('HTTP/1.0 401 Unauthorized');
>> die("Permission Denied");
>> }
>> //your access info... user => pass
>>
>> $userip = (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ?
>> $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER["REMOTE_ADDR"];
>> $allowed_ips = array('212.100.120.40','212.100.120.41','212.100.120.42');
>> if(!in_array($userip,$allowed_ips)
>> {
>> do_auth();
>> }
>> //if were here... then were logged in successfully :)
>> print('Welcome to the control panel <b>'.$userip.'</b>');
>>
>> ----------
>>
>>
>>
>> Good luck
>> *Rob
>sorry parse error in 2nd example replace line...
>
>if(!in_array($userip,$allowed_ips)
>
>with
>
>if(!in_array($userip,$allowed_ips))
>
>;)
>*Rob
Navigation:
[Reply to this message]
|