My Account FAQ How To Resources Support Phone: (480) 624-2500

HTTP Authentication When PHP Runs As 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]


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)));




// 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';
 } else {
   echo "<p>Greetings: </p>".$_SERVER['PHP_AUTH_USER'];
   echo "<p>Password you entered: </p>".$_SERVER['PHP_AUTH_PW'];



Official PHP Website
PHP Scripts
PHP Hosting
Sponsored Links

PHP Web Hosting Example

  Official PHP Website

Cheap PHP Domain Hosting

Advertisements... makes cheap PHP domain hosting easy and is proven by the thousands of clients that choose to host their PHP website. The following is included in all cheap PHP domain hosting packages:

  • Cheap PHP domain hosting price
  • Free installation
  • 100's of free quality features included a no extra cost
  • Flawless uptime
  • Fast technical support (under 10 minutes)

Visit today for the best cheap PHP domain hosting.



How To's


Home   |   Shopping Cart   |   My Account   |   Frequently Asked Questions   |   Support   |   Whois   |   Legal Agreements   |   Partners


Affiliate Programs  |  Chat Rooms  |  Clipart  |  Directories  |  DNS Services  |  Ecommerce  |  FAQs, Help, And Tutorials  |  Flash  |  Fonts
Forums  |  Internet   |  Link Exchange Services  |  Logo Design  |  Marketing  |  Miscellaneous  |  Programming Languages  |  Script Archives
Search Engine Optimization  |  Software  |  Translation Services  |   Web Hosting  |  Webmaster's Resources  |  Webmasters For Hire
Website Content  |  Website Design  |   Website Monitoring  |  Website Promotion  |  Website Templates  |  Domain Name Registration Partners
Cheap Domain Names Registrations

Now Pay with
PayPal Accepted
  Click to Verify Secure Site