WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example 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 ADD CODE EXAMPLES PRINT
Title : .htpasswd class
Categories : PHP, PHP Classes, Authentication Click here to Update Your Picture
Scott Newman
Date : Jun 11th 2005
Grade : 2 of 5 (graded 7 times)
Viewed : 16215
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Scott Newman
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php

// The following class encrypts a password, and writes it to a .htpasswd
// file for use with .htaccess encryption.

// Example usage:
//
// $username="bob";
// $password = "bob";
// $theLine = $htpasswd->genLine($username, $password);
// $htpasswd->writeFile(".htpasswd",$theLine);
//
//
//
// NOTE: Do NOT encrypt the password before calling the genLine function,
// otherwise the password will be encrypted twice, and will not work.
//
// Any questions, IM me www NLH com on AIM.  Enjoy! =)

// START CODE

class htpasswd {

   
// Encrypts given password
   
function encryptPW($thePW){
       
$thePW = crypt(trim($thePW),base64_encode(CRYPT_STD_DES));
        return
$thePW;
    }

   
// Calls the encryptPW function, generates the line for writing
   
function genLine($username,$password){
       
$encrypted_password = encryptPW($password);
        return
"$username:$encrypted_password";
    }

   
// Writes data to the file
   
function writeFile($theFile,$theLine){
       
$fp = fopen($theFile, "a");
       
$orig_size = filesize($theFile);

       
// Trims all whitespace
       
$theContents = file_get_contents($theFile);
       
$strippedContents = str_replace(" ", "", $theContents);

       
ftruncate($fp, 0);

       
fwrite($fp, $strippedContents);

       
// Sets file pointer to the end of the file
       
fseek($fp, filesize($theFile));

       
// If this is the first entry in the file, do not add a new line before writing
       
if($orig_size == 1){
           
fwrite($fp, "$theLine");
        }else{
           
// If this is not the first entry, write the data on a new line in the file
           
fwrite($fp, "$theLine");
        }
       
fclose($fp);
    }

}

// END CODE
?>



Simple and fast user authentication
Categories : PHP, PHP Classes, Authentication
Use of bitmasks to represent permissions
Categories : PHP, Authentication, Bitwise Operators, Security, PHP Classes
Access_user Class - an easy to use system for protecting pages and register users.
Categories : PHP, Classes and Objects, Object Oriented, PHP Classes, Authentication
.htpassword manager for apache
Categories : PHP, PHP Classes, Authentication, Apache
Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support
Categories : PHP, FTP, Filesystem, PHP Classes, Compression
DbObject - A PHP wrapper for working with various databases
Categories : Databases, PHP, PHP Classes
Authorize.net AIM Interface Class v1.0.0
Categories : PHP, PHP Classes, Ecommerce, Payment Gateways
Browser Detecor Class
Categories : PHP Classes, PHP, HTML
filesplit : Split big text files in multiple small ones
Categories : PHP, Log Files, Filesystem, PHP Classes
A File Browser Class.To Read Drives,Directories and Files .Files writing is also possible
Categories : PHP, PHP Classes, Filesystem
Specify your connection settings and create a link to a MySQL database.
Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides
Filter - A simple class that lets you use multiple functions to create custom filters.
Categories : PHP, PHP Classes, Strings
Customizable Calendar Class
Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar
HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout.
Categories : Graphics, Arrays, PHP, PHP Classes, Charts and Graphs
Client classes for Dictionary servers UPDATED: 2000-06-06
Categories : Network, Search, Complete Programs, PHP Classes, PHP