ropu:
Hi, there is an issue with CGI configurations.
Basic Authentication in not "compatible" with PHP over CGI (see php manual, and previous posts)
$_SERVER var cant get basic auth info
im doing a script to generate a pair of .htaccess .htpasswd to generate that auth using them.
im testing it in my srvs and delivered ASAP so you can test it.
ropu
Here is a little script to create the .htaccess .htpasswd files to use Basic Authentication with CGI PHP authentication.
Please, try it and let me know how it works for you.
Note that the apache config to allow .htaccess files must be present
Should look similar to this
<Directory /home/*/public_html>
AllowOverride All
</Directory>
```Have a look to the README in the Script, you must comment PHP Validation
```php
<?php
// For function rand_salt_crypt()
// Copyright (C) 2004,2005 Jarno Elonen <[email protected]>
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * The name of the author may not be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// .htaccess .htpasswd pair for Google Checkout Basic authentication on CGI php installations
// Coded by Ropu
// 02-14-2006 st. Valentine's day :D
/*
* README:
*
* NOTE: This must be used if you run PHP over CGI
*
* Run this script, fill the form with your Google Checkout Merchant Id/Key
* and with the absolute path to your catalog/googlechekout/ directoy.
* ie. /home/ropu/public_html/cart/googlecheckout
*
* Click "Create"
*
* Copy the contents for .htaccess and .htpasswd into those files and place
* them in that directory.
*
* Remove or comment from googlecheckout/responsehandler.php the folowing code:
*
*
[code]
//Parse the HTTP header to verify the source.
if(isset($HTTP_SERVER_VARS['PHP_AUTH_USER']) && isset($HTTP_SERVER_VARS['PHP_AUTH_PW'])) {
$compare_mer_id = $HTTP_SERVER_VARS['PHP_AUTH_USER'];
$compare_mer_key = $HTTP_SERVER_VARS['PHP_AUTH_PW'];
}
else {
error_func("HTTP Basic Authentication failed.\n");
exit(1);
}
$googlepayment = new googlecheckout();
$merchant_id = $googlepayment->merchantid;
$merchant_key = $googlepayment->merchantkey;
if($compare_mer_id != $merchant_id || $compare_mer_key != $merchant_key) {
error_func("HTTP Basic Authentication failed.\n");
exit(1);
}
[/code]
*
* Test the responsehandler.php with the responsehandler_test.php
*
*/
if(isset($_POST['submit'])) {
$user = $_POST['id'];
$pass = $_POST['key'];
$crypt_pass = rand_salt_crypt($pass);
echo "<xmp>.htaccess file:\n<<<Start---\n";
echo 'AuthName "Google checkout Basic Authentication"' . "\n";
echo 'AuthType Basic' . "\n";
echo 'AuthUserFile ' . $_POST['path'] . "/.htpasswd\n";
echo 'require valid-user' . "\n---End>>>\n";
echo "\n\n.htpasswd file:\n<<<Start---\n";
echo $user . ":" . $crypt_pass ."\n---End>>>\n</xmp>\n";
}
?>
<title>.htaccess .htpasswd pair for Google Checkout Basic authentication on CGI php installations</title>
<h2>.htaccess .htpasswd pair for Google Checkout Basic authentication on CGI php installations</h2>
<form action="" method="post">
<table>
<tr>
<th align="right">Merchant ID:</th><td><input type="text" value="<?=@$_POST['id'];?>" name="id" size="40"/></td>
</tr>
<tr>
<th align="right">Merchant Key:</th><td><input type="text" value="<?=@$_POST['key'];?>" name="key" size="40"/></td>
</tr>
<tr>
<th align="right">Absolute path to googlecheckout/ :</th><td><input type="text" value="<?=@$_POST['path'];?>" name="path" size="40"/></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" name="submit" value="Create"/></td>
</tr>
</table>
</form>
<?
// Generates a htpasswd compatible crypted password string.
function rand_salt_crypt( $pass )
{
$salt = "";
mt_srand((double)microtime()*1000000);
for ($i=0; $i<CRYPT_SALT_LENGTH; $i++)
$salt .= substr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./", mt_rand() & 63, 1);
return crypt($pass, $salt);
}
?>
```ropu