Location: PHPKode > projects > phpMySOAP > phpMySOAP/authentification.php
<?php

/**
 * @author Korbinian Ober
 * @copyright 2010 tuxphr34k media software solutions
 * @version 0.1a
 */

/**
 * authenticate()
 * 
 * Forces the browser / client to authenticate himself for this service.
 * 
 * @return exit();
 */
function authenticate() {
    header('WWW-Authenticate: Basic realm="'.$config['servicename'].' Authentification"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'You are not authorized to view this page.';
    exit;    
}
/**
 * starts authentification of the client
 * 
 * you can either use one of the authentification methods, or even both if you need to
 */
$credentials = null;
if (!isset($_SERVER['PHP_AUTH_USER'])) {
    authenticate();
} else {
    $credentials['username'] = $_SERVER['PHP_AUTH_USER'];
    $credentials['password'] = $_SERVER['PHP_AUTH_PW'];
    $credentials['passwordbw'] = strrev($credentials['password']);
    if (isset($config['auth_fixed'])) {
        // fixed authentification is enabled
        foreach ($config['auth_fixed'] as $auth) {
            if (($auth['user'] == $credentials['username']) && ($auth['pass'] == $credentials['password'])) {
                if (!defined('AUTH_USER')) {
                    define('AUTH_USER', $credentials['username']);
                    define('AUTH_PASS', $credentials['password']);
                    break;
                }
            }
        }
    }
    // mysql authentification is enabled
    if (isset($config['auth_sql']) && !defined('AUTH_USER')) {
        $config['auth_sql'] = str_replace(
            array('@@0@@', '@@1@@', '@@2@@'),
            array('\''.mysql_real_escape_string($credentials['username']).'\'', '\''.mysql_real_escape_string($credentials['password'], $db).'\'', '\''.mysql_real_escape_string($_SERVER['REMOTE_ADDR'], $db).'\''),
            $config['auth_sql']
        );
        $query = mysql_query($config['auth_sql'], $db);
        if (mysql_num_rows($query) > 0) {
                if (!defined('AUTH_USER')) {
                    define('AUTH_USER', $credentials['username']);
                    define('AUTH_PASS', $credentials['password']);
                }            
        }
    }
    if (!defined('AUTH_USER'))
        authenticate();
}
Return current item: phpMySOAP