Re: Subject: Re: User Authentication...

From: Date: Mon, 16 Jun 2003 12:28:30 +0000
Subject: Re: Subject: Re: User Authentication...
Groups: php.windows 
Request: Send a blank email to php-windows+get-20345@lists.php.net to get a copy of this message
Try this. Please note that on windows you *cannot* raise a http auth box this way (PHP_AUTH_USER is not defined for Apache on windows), so you will need to use this on your live unix Apache/PHP server :
        function getUserAuthPW() {
// If present, set user Authenticate Password box values
                global $_SERVER;
                if (isset($_SERVER["PHP_AUTH_USER"])) {
                        $username=safestring($_SERVER["PHP_AUTH_USER"]);
                        $password=safestring($_SERVER["PHP_AUTH_PW"]);
                        return true;
                } else {
                        header("WWW-Authenticate: Basic realm=\"CaptionKit\"");
                        header("HTTP/1.0 401 Unauthorized");
                        echo "You must enter a valid login ID and password to access this resource\n";
                        exit;
                }
        }
What this does is to check for PHP_AUTH_USER and if it's not defined, raises a 401 error. The client interprets this as a request to enter user name & password, and brings up the grey box you see using .htaccess / .htpasswd files. The function safestring just adds slashes if there are characters which need escaping for your database (some people might just 'addslashes()' but I do a little more first, like trim and htmlspecialchars). Cheers - Neil Smith. Please note : I do not accept email from hotmail, yahoo, AOL or msn accounts. All such mail *will* be bounced and deleted without being read. Thankyou for your understanding. At 07:36 16/06/2003 +0000, you wrote:
Message-ID: <20030615193745.49877.qmail@pb1.pair.com> To: php-windows@lists.php.net Reply-To: "Guru P Chaturvedi" <bangboy2k2@hotmail.com> From: "Guru P Chaturvedi" <bangboy2k2@hotmail.com> Date: Mon, 16 Jun 2003 01:16:53 +0530 Subject: Re: User Authentication... MIME-Version: 1.0 Hi, Any clues...please?!


« previous php.windows (#20345) next »