Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199903

[PHP3] .htpaaswd final (was:Re: [PHP3] .htpasswd) From: Matthew Joseff (mjoseff <email protected>)
Date: 03/06/99

Here's the final (working) script I came up with:

I took my values out. Now, I'm working with procmail to split this script
up to only run the htpasswd part when the user replies to the email
($message).

<?

$message="[your message]";

mail ($email, "[Subject]", $message, "From"[return addy]");

$htpasswdfile="[passwd file]";

#function useradd($username,$password) {

mysql_connect(localhost,$db,[paswd]);
mysql_select_db($db);

$there="SELECT * from $table where username=('$username')";
$result=MYSQL_QUERY($there);
        IF (MYSQL_NUM_ROWS($result)>0){ PRINT "<html>
$username is already in use. </html>";

EXIT ();
}
else{

$adduser="insert into $table values ('$username', '$password', '$email')";

$result=mysql_query($adduser);

mysql_query($result);

mysql_close;

        while (file_exists($htpasswdfile.".lock")) {
                sleep(1);
                clearstatcache();
        }

        symlink($htpasswdfile,$htpasswdfile.".lock");
        $userfile = file($htpasswdfile);

        for ($i=0;$i<count($userfile);$i++) {
                $uppairs[] = explode(":",$userfile[$i]);
                $uppairs[$i][1] = trim($uppairs[$i][1]);
               #MySQL above checks for redundancy
                # if ($uppairs[$i][0] == $username) {
                # unlink($htpasswdfile.".lock");
                 # return -1;
                #}
        }
        $cryptpass=crypt($password);
        $uoutfile .= $username.":".$cryptpass."\n";

        $ufp = fopen($htpasswdfile,"a");
        fputs($ufp,$uoutfile);
        fclose($ufp);
        unlink($htpasswdfile.".lock");
}

?>

-- 
Matthew Joseff, Web Development
RCN Corp. 703-321-2410
www.rcn.com NASDAQ: RCNC 

-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3 List administrator: zeev-list-admin <email protected>