Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Sobota, 14. jún 2025

Súbor: [Platon] / phpWebFileManager / plugins / vsauth.php (stiahnutie)

Revízia 1.1, Sat Dec 17 16:52:46 2005 UTC (19 years, 6 months ago) by nepto

Very old pluging by Doug Hockinson commited into the CVS.

<?php

// Adapted from tutorial at http://www.zend.com/zend/tut/authentication.php

$auth = false; // Assume user is not authenticated

function echo_html($string)
{
    echo '<html><body><br><br><center><h3>'.$string.'</h3></center></body></html>';
}

if(isset($PHP_AUTH_USER) && isset($PHP_AUTH_PW)) {

    // Read the entire file into the variable $file_contents

    $filename = $opts['log']['users']; // $filename = '/path/to/file.txt'; 

    if($fp = fopen($filename, 'r')){

        $file_contents = fread($fp, filesize($filename));

        fclose($fp);

        // Explode: Unix \n and Windows \r\n

        $lines = explode("\r\n", $file_contents ); // Place the individual lines from the file contents into an array.

        // Split each of the lines into a username and a password pair and attempt to match them to $PHP_AUTH_USER and $PHP_AUTH_PW.

        foreach($lines as $line) {

            @list($username, $password) = explode(':', $line);

            if(($username == "$PHP_AUTH_USER") && ($password == "$PHP_AUTH_PW")) {

                $auth = true; // A match is found, meaning the user is authenticated. 

                break; // Stop the search.

            }
        }

    }else{
        header('WWW-Authenticate: Basic realm="Private"');
        header('HTTP/1.0 401 Unauthorized');
        echo_html('User List Unavailable');
        exit;
    }

};

if(!$auth) {
    header('WWW-Authenticate: Basic realm="Private"');
    header('HTTP/1.0 401 Unauthorized');
    echo_html('Authentication Required');
    exit;
}else{
    // echo $PHP_AUTH_USER;
}

?>

Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok