Version: 1
Type: Full Script
Category: Other
License: GNU General Public License
Description: This Code i have tested on Apache , here user is authenticated user username james and password smith , the program sends mail to the System Admin informing who logged in and When , Easy to use and u can modify to suit your requirements
<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="Author" content="james"> <meta name="GENERATOR" content="Mozilla/4.75 [en] (Win98; U) [Netscape]"> <title>secure</title> </head> <body> <? <br> if(($PHP_AUTH_USER == "james") AND ($PHP_AUTH_PW == "smith")) <br> { <br> print("<HTML>n"); <br> print("<HEAD>n"); <br> print("<TITLE>Welcome to Members Area</TITLE>n"); <br> print("</HEAD>n"); <br> print("<BODY>n"); <br> print("You have logged in successfully!<BR>n"); <br> $username = "James Smith"; <br> $email = "[email protected]"; <br> $mailsubject = "$PHP_AUTH_USER has logged in "; <br> $Fromname = "James Smith"; <br> $Fromaddress = "James Smith"; <br> <br> $today = date("g:i a"); <br> $time=$today; <br> $x= date("U"); <br> $m = date("M"); <br> $x1 =date(" dS, F Y",$x); <br> $msg = "This is to inform System Administrator That $PHP_AUTH_USER had logged in with $PHP_AUTH_PW as password on $x1 "; <br> <br> if (mail($username." <".$email.">", $mailsubject, $msg, "From: ".$Fromname." <".$Fromaddress.">nContent-Type: text/html; charset=iso-8859-1")) <br> { <br> print ("Mail Sent To $username<br><br>"); <br> print ($msg); <br> } <br> else <br> { <br> print ("Mail Dead"); <br> } <br> print("</BODY>n"); <br> print("</HTML>n"); <br> } <br> else <br> { <br> header("WWW-Authenticate: Basic realm="Protected Area Members Only""); <br> header("HTTP/1.0 401 Unauthorized"); <br> print("This page is protected by HTTP Authentication.<br>n"); <br> print("<B>james</B> for the username, and smith is password "); <br> } <br>?> <br> <br> <br> </body> </html>