HTTP Authentication When PHP Runs As A CGI/PHPSuExec

PHP is a feature-rich programming language that includes simple HTTP authentication. Unfortunately, if PHP is running under CGI then PHP scripts cannot use HTTP authentication. The workaround for this problem is to use mod_rewrite to pass HTTP authentication info to scripts as a GET parameter.

The following are step-by-step instructions on how to get HTTP authentication working when PHP is running as a CGI/PHPSuExec.

Step 1:
Create a plain text file using a text editor such as Windows Notepad.

Step 2:
Add the following text...

 

<IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>

 

Step 3:
Save the file as a plain text file. Name the file ".htaccess"

Step 4:
Upload the .htaccess file in ASCII mode to your web space using an FTP application.

Step 5:
Add the following in your PHP script right before your user/pass check routine.
 

 

list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));

 

Example:

 

<?php
// split user/pass parts
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));

// open user/pass prompt
if (!isset($_SERVER['PHP_AUTH_USER'])) {
   header('WWW-Authenticate: Basic realm="Your Realm"');
   header('HTTP/1.0 401 Unauthorized');
   echo 'Text to send if Cancel button is used';
   exit;
 } else {
   echo "<p>Greetings: </p>".$_SERVER['PHP_AUTH_USER'];
   echo "<p>Password you entered: </p>".$_SERVER['PHP_AUTH_PW'];
 }
?>

 


Buy one of our cheap personal web hosting packages today.
 

PHP CGI/SuExec

Official PHP Website
PHP Scripts
PHP Web Hosting

Cheap PHP Personal Web Hosting


Cheap PHP Personal Web Hosting
  

 

Crontab Cron Jobs support is free and is included in all web hosting packages. You can easily setup custom Crontab Cron Jobs using the control panel.

 

  

Cheap Personal Web Hosting

HostCherry.com provides cheap personal web hosting while providing the very best quality service in the industry. We keep expenses down by cutting all unnecessary costs and by utilizing the latest open source software allowing us to provide the most reliable personal web hosting.

When you choose one of our cheap personal web hosting packages, you receive 100's of features providing everything your website needs to flourish online. Our cheap personal web hosting provides an abundant amount disk space and bandwidth, shopping carts, blogs, forums, image galleries, and more.
You deserve a cheap personal web hosting provider with rock-solid reliability. Our robust network infrastructure ensures maximum uptime and superior performance for our cheap personal web hosting packages. Our network architecture utilizes the Enterprise routing and switching engines from Juniper and Cisco. We utilize Juniper M20 routers as border routers, Cisco 6500 series switches in our distribution layer and Cisco 6500 switches in our aggregation layers, and Cisco 3500 and 2900 series switches at the client layer. Our network is fully meshed and redundant with 8 backbone providers for a total of 28 Gbps of available bandwidth.

 
Being the leading cheap personal web hosting provider in the industry, our goal is to provide our customers comprehensive resolutions to problems in a quick timeframe. Our help desk system routes technical support questions directly to support team members that are best able to resolve your issue. Our current average help desk response time is 9 minutes 58 seconds.