WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this Article to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES SUBMIT AN ARTICLE PRINT
Title : Protecting PHP Scripts with HTTP Authorization
Categories : PHP, HTTP, Security, Authentication
phpfreaks.com
phpfreaks.com
Date : 2003-09-20
Grade : 0 of 5 (graded 0 times)
Viewed : 8123
Search : More Articles by phpfreaks.com
Action : Grade This Article
Tools : My Favotite Articles


  Submit your own code examples 
 


People like and have always liked keeping secrets. It's in the essence of man. So there are times when you want to write a PHP script accesibile only to you, or a select few. The answer to your needs is using a password. There is more than one way to password-protect a script, but we're going to talk about the most efficient one: HTTP Authorization, as implemented in PHP. HTTP Authorization has been available for some time now, and is usually achieved by using ".htpasswd" files, along with accompanying ".htpasswd". But since PHP arrived, HTTP password protection became much easier.
The first step in protecting a script with HTTP Auth is to make that script send HTTP Code 401 to users that don't send a username/password pair, which means "You need to send a password to see me". This is easily achieved in PHP via the Header() function.
The code flow on that is, using the $auth variable to describe the authorization state of the current user:


<?
if ( $auth != 1 ) { //if the user isn't authenticated

header( "WWW-Authenticate: Basic realm="Authorization Required!"" ); //this makes the browser generate a login box
header( "HTTP/1.0 401 Unauthorized" ); //this tells the browser that further viewing is not permitted
echo 'Authorization Required!'; //and this gets echoed if the user doesn't enter the correct username/password pair
exit; //this makes the script exit, and the user session ends. No script for you!
}
?>


Basically what that means is that any user not sending in his HTTP request a correct user/password pair is not going to see the page, and have a standard HTTP Login box appear (generated by his web browser). As we previously discussed this, HTTP Authorization is a long user method and 99% of browsers are fully capable of handling this sort of message.

On the next page, we'll discuss how to get PHP to check a user/password pair sent by the user.

Read More...









Writing A Port Scanner In PHP
Categories : PHP, HTTP, Security
User Authentication With patUser (part 2)
Categories : PHP, Authentication, Security
Referer Statistics
Categories : PHP, MySQL, HTTP, Databases
PHP5: Designing And Using Interfaces
Categories : PHP, Object Oriented, Interfaces, PHP Classes, Security
Send SMS Thru HTTP
Categories : PHP, SMS, HTTP
PHP for Beginners by a Beginner: Simple Login, Logout, and Session Handling
Categories : PHP, Sessions, Authentication
How to Develop a Simple yet Secure Password System
Categories : Authentication, Security
PHP, MySQL and Authentication 101
Categories : PHP, Databases, MySQL, Authentication
User Authentication With Apache and PHP
Categories : PHP, Web Servers, Apache, Authentication
Working with Permissions in PHP, Part 1
Categories : PHP, Security
Uploading files to the server with PHP
Categories : PHP, File System, HTML and PHP, HTTP
Watching The Web
Categories : PHP, Databases, MySQL, HTTP, MD5
Exploring Session Security In PHP Web Applications
Categories : PHP, Security, Sessions, Web Applications
Developing a Security Policy, by Anna Johnson
Categories : Other, Security, Site Planning
Generating One-Time URLs with PHP
Categories : PHP, URLs