cancel
Showing results for 
Search instead for 
Did you mean: 

[PAYH] Protected Directories on the PAYH platform - RESOLVED!

SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

[PAYH] Protected Directories on the PAYH platform - RESOLVED!

For the benefit of all readers of this post...
Try out the new platform! Plesk is a really easy to use control panel and offers lots of features not seen by PN users before.
The Protected Directories on the PAYH platform is a very useful feature and one i would like to explore further.
But I have a question...
A user called 'Fred' logs on to my protected area via a dialog box that looks like the one driven by .htaccess protection methods. (Maybe it is?)
Anyway, once Fred has sucessfully logged on, he can write news articles and those news articles will be displayed as being authored by him which means that the PHP scripting needs to remeber who logged on.
I think you would normally refer to HTTP_USER or similar but this can not be done on the PN platform because of limitations in the PHP.ini file (I beleive)
Will this work on the new PAYH platform?
1 REPLY 1
SoulBriski
Grafter
Posts: 179
Registered: ‎15-06-2007

Re: Protected Directories on the PAYH platform - RESOLVED!

I really should do more homework before I post stupid questions Huh
I was being lazy and trying to remember the variable name for getting the user info but the paragraph and code below, kindly borrowed from http://uk.php.net/features.http-auth is exactly what I was after.
HTTP authentication with PHP
The HTTP Authentication hooks in PHP are only available when it is running as an Apache module and is hence not available in the CGI version. In an Apache module PHP script, it is possible to use the header() function to send an "Authentication Required" message to the client browser causing it to pop up a Username/Password input window. Once the user has filled in a username and a password, the URL containing the PHP script will be called again with the predefined variables PHP_AUTH_USER, PHP_AUTH_PW, and AUTH_TYPE set to the user name, password and authentication type respectively. These predefined variables are found in the $_SERVER and $HTTP_SERVER_VARS arrays. Both "Basic" and "Digest" (since PHP 5.1.0) authentication methods are supported. See the header() function for more information.
Basic HTTP Authentication example
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Text to send if user hits Cancel button';
    exit;
} else {
    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
    echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?>

This doesn't work on the PN platform but does in the new PAYH version