Forum How do I...?

Password protection (Basic authorization)

lindm
I want Prince to access and print a password protected page. From previous discussions I see that --http-user and --http-password have been implemented but can't find any documentation regarding the use of this.

The current code (top part with auth) of my php page to be printed is:


<?php 
function CheckAccess() 
{ 
$userid ="id";
$userpass = "pass";

$result = (isset($_SERVER["PHP_AUTH_USER"]) && 
            $_SERVER["PHP_AUTH_USER"] == $userid && 
            $_SERVER["PHP_AUTH_PW"] == $userpass); 
if (!$result) 
  { 
   header(\'WWW-Authenticate: Basic realm="Test restricted area"\'); 
   header("HTTP/1.0 401 Unauthorized"); 
   return false; 
  } 
  else 
   return true; 
} 
Checkaccess();
?>
HTMLCODE HERE



So I see two solutions:

1. I get --http-user and --http-password working
2. I some way make the authorization code above be overridden if the request comes from Prince (for instance if HTTP_REFERER is prince...tried but no success).

Would be very greatful for help on both parts.

Thanks.
mikeday
Option 1 is better, as option 2 would allow anyone to access the page by spoofing their user-agent header.

We have just updated the Prince PHP interface to support basic HTTP authentication, with two new methods: setHttpUser() and setHttpPassword().