mauth.php


<?php

//##auth
define( "AUTH_UNAUTH", -1 );
define( "AUTH_GUEST", 0 );
define( "AUTH_USER", 1 );
define( "AUTH_POWERUSER", 2 );
define( "AUTH_ADMIN", 3 );

$ma_authtype = AUTH_UNAUTH;
$ma_name = array( "GUEST", "USER", "POWERUSER", "ADMIN" );

//basic認証サポート
function ma_AuthUser( $pwfile )
{
    if( !isset($_SERVER['PHP_AUTH_USER']) )
    {
        return -1;
    }
    else
    {
        $p_data = file($pwfile);
        for( $i=0; $i<count($p_data); $i++ )
        {
            list($group,$id,$pass) = explode(":",$p_data[$i]);
            if( $id == $_SERVER['PHP_AUTH_USER'] &&
                $pass == crypt( $_SERVER['PHP_AUTH_PW'],crypt($_SERVER['PHP_AUTH_PW'],$pass) ) )
            {
                global $ma_authtype;
                $ma_authtype = $group;
                return $group;
            }
        }
    }

    return -2;
}


//現在の権限得る
function ma_GetAuth()
{
    global $ma_authtype;
    return $ma_authtype;
}

function ma_GetAuthS()
{
    global $ma_authtype;
    global $ma_name;

    return $ma_name[$ma_authtype];
}

?>