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'];
 }
?>

 


Check out our cheap blog web hosting packages today.
 

PHP CGI/SuExec

Official PHP Website
PHP Scripts
PHP Web Hosting

Cheap PHP Blog Web Hosting


Cheap PHP Blog 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.

 

  

blog hosting best value
Cheap Blog Hosting

Francey.org provides blog hosting at the very best quality in the industry. By eliminating all unnecessary costs and by utilizing the latest open source software, we can keep costs down and provide our clients with highly reliable and cheap blog web hosting.

blog hosting quality features
When you choose one of our blog hosting packages, you receive 100's of features providing everything your website needs to flourish online. You are not limited to only running a blog with our service. With our cheap blog web hosting you can install shopping carts, forums, image galleries, chat rooms, and more all for free at the click of the mouse.
reliable blog hosting
You deserve a blog hosting provider with rock-solid reliability. Our robust network infrastructure ensures maximum uptime and superior performance for our blog 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 backbone providers for a total of 100 gigabits /second of available bandwidth.
blog hosting technical support
 
Being the leading cheap blog web hosting provider in the industry, our goal is to provide our customers comprehensive resolutions to problems in a quick timeframe. Our technical support 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 6 minutes 20 seconds.