A simple login script that you can modify to suit your needs. It use a session to store data in a session file submited by the page. In this example the username and password will be save in the session file created by php.
I introduce the following files.
index.php -script file as name of your protected site.
login.html -script file as your login page.
user -folder
test.txt -account file under folder(user)
test|password -the content of the test.txt, username is test password is password
What you are going to do?
1. In your php.ini, enable session.use_cookies and specify session.save_path
2. Create a folder name "user" under it create an account file example: "test.txt"
3. The content of your test.txt will be like this
test|password
*note
account filename is the same as username.
5.copy the script and place it to your web directory.
4.edit the index.php and change the $root=to the actual full path where folder(user) is located.
5.and insert the code of your protected website as shown in the script.
<!//your script starts here when account is valid--->
<! insert your code here.....---->
Password Protected Website<br>
YOU ARE LOGIN AS <? echo $username ?> <br>
<a href=<?php echo"$SCRIPT_NAME";?>?logout=1>Logout</a>
<!//your script ends here--->
6:login and use test as username and password as password.
Code:
[COLOR=#000000][COLOR=#0000CC]<?php
$root[/COLOR][COLOR=#006600]=[/COLOR][COLOR=#CC0000]"c:/inetpub/wwwroot/folder/"[/COLOR][COLOR=#006600]; [/COLOR][COLOR=#FF9900]//full path of folder(user)
[/COLOR][COLOR=#0000CC]session_start[/COLOR][COLOR=#006600]();
[/COLOR][COLOR=#0000CC]$_SESSION[/COLOR][COLOR=#006600][[/COLOR][COLOR=#CC0000]'username'[/COLOR][COLOR=#006600]] = [/COLOR][COLOR=#0000CC]$username[/COLOR][COLOR=#006600];
[/COLOR][COLOR=#0000CC]$_SESSION[/COLOR][COLOR=#006600][[/COLOR][COLOR=#CC0000]'password'[/COLOR][COLOR=#006600]] = [/COLOR][COLOR=#0000CC]$password[/COLOR][COLOR=#006600];
[/COLOR][COLOR=#FF9900]//if (isset($logout))
//{
[/COLOR][COLOR=#006600]if ([/COLOR][COLOR=#0000CC]$logout[/COLOR][COLOR=#006600]==[/COLOR][COLOR=#0000CC]true[/COLOR][COLOR=#006600])
{
unset([/COLOR][COLOR=#0000CC]$HTTP_SESSION_VARS[/COLOR][COLOR=#006600][[/COLOR][COLOR=#CC0000]'username'[/COLOR][COLOR=#006600]]);
unset([/COLOR][COLOR=#0000CC]$HTTP_SESSION_VARS[/COLOR][COLOR=#006600][[/COLOR][COLOR=#CC0000]'password'[/COLOR][COLOR=#006600]]);
echo[/COLOR][COLOR=#CC0000]"<meta http-equiv=refresh content=\"0;URL=$SCRIPT_NAME\">"[/COLOR][COLOR=#006600];
}
[/COLOR][COLOR=#FF9900]//}
[/COLOR][COLOR=#006600]if ([/COLOR][COLOR=#0000CC]file_exists[/COLOR][COLOR=#006600]([/COLOR][COLOR=#0000CC]$root[/COLOR][COLOR=#006600].[/COLOR][COLOR=#CC0000]"user/"[/COLOR][COLOR=#006600].[/COLOR][COLOR=#0000CC]$username[/COLOR][COLOR=#006600].[/COLOR][COLOR=#CC0000]".txt"[/COLOR][COLOR=#006600]))
{[/COLOR][COLOR=#FF9900]//1
[/COLOR][COLOR=#0000CC]$fp[/COLOR][COLOR=#006600]=[/COLOR][COLOR=#0000CC]fopen[/COLOR][COLOR=#006600]([/COLOR][COLOR=#0000CC]$root[/COLOR][COLOR=#006600].[/COLOR][COLOR=#CC0000]"user/"[/COLOR][COLOR=#006600].[/COLOR][COLOR=#0000CC]$username[/COLOR][COLOR=#006600].[/COLOR][COLOR=#CC0000]".txt"[/COLOR][COLOR=#006600],[/COLOR][COLOR=#CC0000]"r"[/COLOR][COLOR=#006600]);
[/COLOR][COLOR=#0000CC]$contents[/COLOR][COLOR=#006600]=[/COLOR][COLOR=#0000CC]fread[/COLOR][COLOR=#006600]([/COLOR][COLOR=#0000CC]$fp[/COLOR][COLOR=#006600],[/COLOR][COLOR=#0000CC]filesize[/COLOR][COLOR=#006600]([/COLOR][COLOR=#0000CC]$root[/COLOR][COLOR=#006600].[/COLOR][COLOR=#CC0000]"user/"[/COLOR][COLOR=#006600].[/COLOR][COLOR=#0000CC]$username[/COLOR][COLOR=#006600].[/COLOR][COLOR=#CC0000]".txt"[/COLOR][COLOR=#006600]));
[/COLOR][COLOR=#0000CC]fclose[/COLOR][COLOR=#006600]([/COLOR][COLOR=#0000CC]$fp[/COLOR][COLOR=#006600]);
[/COLOR][COLOR=#0000CC]$info[/COLOR][COLOR=#006600]=[/COLOR][COLOR=#0000CC]explode[/COLOR][COLOR=#006600]([/COLOR][COLOR=#CC0000]"|"[/COLOR][COLOR=#006600],[/COLOR][COLOR=#0000CC]$contents[/COLOR][COLOR=#006600]);
[/COLOR][COLOR=#0000CC]$username1[/COLOR][COLOR=#006600]=[/COLOR][COLOR=#0000CC]$info[/COLOR][COLOR=#006600][[/COLOR][COLOR=#0000CC]0[/COLOR][COLOR=#006600]];
[/COLOR][COLOR=#0000CC]$password1[/COLOR][COLOR=#006600]=[/COLOR][COLOR=#0000CC]$info[/COLOR][COLOR=#006600][[/COLOR][COLOR=#0000CC]1[/COLOR][COLOR=#006600]];
if([/COLOR][COLOR=#0000CC]$password1[/COLOR][COLOR=#006600]==[/COLOR][COLOR=#0000CC]$HTTP_SESSION_VARS[/COLOR][COLOR=#006600][[/COLOR][COLOR=#CC0000]'password'[/COLOR][COLOR=#006600]])
{[/COLOR][COLOR=#FF9900]//2
[/COLOR][COLOR=#0000CC]?>
[/COLOR]<!//your script starts here when account is valid--->
<! Insert your code here ---->
Password Protected Website<br>
YOU ARE LOGIN AS [COLOR=#0000CC]<? [/COLOR][COLOR=#006600]echo [/COLOR][COLOR=#0000CC]$username ?>[/COLOR] <br>
<a href=[COLOR=#0000CC]<?php [/COLOR][COLOR=#006600]echo[/COLOR][COLOR=#CC0000]"$SCRIPT_NAME"[/COLOR][COLOR=#006600];[/COLOR][COLOR=#0000CC]?>[/COLOR]?logout=1>Logout</a>
<!//your script ends here--->
[COLOR=#0000CC]<?php
[/COLOR][COLOR=#006600]}[/COLOR][COLOR=#FF9900]//2
[/COLOR][COLOR=#006600]else
{[/COLOR][COLOR=#FF9900]//2
[/COLOR][COLOR=#0000CC]$err[/COLOR][COLOR=#006600]=[/COLOR][COLOR=#CC0000]"Invalid Password"[/COLOR][COLOR=#006600];
include([/COLOR][COLOR=#CC0000]"login.html"[/COLOR][COLOR=#006600]);
unset([/COLOR][COLOR=#0000CC]$HTTP_SESSION_VARS[/COLOR][COLOR=#006600][[/COLOR][COLOR=#CC0000]'username'[/COLOR][COLOR=#006600]]);
unset([/COLOR][COLOR=#0000CC]$HTTP_SESSION_VARS[/COLOR][COLOR=#006600][[/COLOR][COLOR=#CC0000]'password'[/COLOR][COLOR=#006600]]);
[/COLOR][COLOR=#0000CC]session_destroy[/COLOR][COLOR=#006600]();
}[/COLOR][COLOR=#FF9900]//2
[/COLOR][COLOR=#006600]}[/COLOR][COLOR=#FF9900]//1
[/COLOR][COLOR=#006600]else
{
[/COLOR][COLOR=#0000CC]$err[/COLOR][COLOR=#006600]=[/COLOR][COLOR=#CC0000]"Invalid Username"[/COLOR][COLOR=#006600];
include([/COLOR][COLOR=#CC0000]"login.html"[/COLOR][COLOR=#006600]);
unset([/COLOR][COLOR=#0000CC]$HTTP_SESSION_VARS[/COLOR][COLOR=#006600][[/COLOR][COLOR=#CC0000]'username'[/COLOR][COLOR=#006600]]);
unset([/COLOR][COLOR=#0000CC]$HTTP_SESSION_VARS[/COLOR][COLOR=#006600][[/COLOR][COLOR=#CC0000]'password'[/COLOR][COLOR=#006600]]);
[/COLOR][COLOR=#0000CC]session_destroy[/COLOR][COLOR=#006600]();
}
[/COLOR][COLOR=#0000CC]?>
[/COLOR]
login.html
<html>
<head><title>login</title></head>
<body bgcolor=gold>
<center>
<form method=post action=[COLOR=#0000CC]<? [/COLOR][COLOR=#006600]echo [/COLOR][COLOR=#CC0000]"$SCRIPT_NAME"[/COLOR][COLOR=#006600]; [/COLOR][COLOR=#0000CC]?>[/COLOR]>
<table border=1 cellpadding=3 celspacing=3 align=center width=50%>
<tr><td colspan=2 align=center>Login</td></tr>
<tr><td colspan=2 align=center>[COLOR=#0000CC]<?php [/COLOR][COLOR=#006600]if (isset([/COLOR][COLOR=#0000CC]$username[/COLOR][COLOR=#006600])){if ([/COLOR][COLOR=#0000CC]$logout[/COLOR][COLOR=#006600]==[/COLOR][COLOR=#0000CC]false[/COLOR][COLOR=#006600]){if(isset([/COLOR][COLOR=#0000CC]$err[/COLOR][COLOR=#006600])){echo [/COLOR][COLOR=#CC0000]"$err"[/COLOR][COLOR=#006600];}}}[/COLOR][COLOR=#0000CC]?>[/COLOR]</td></tr>
<tr><td>Username:</td><td><input type=text name=username size="20"></td><tr>
<tr><td>Password:</td><td><input type=password name=password size="20"></td><tr>
<tr><td colspan=2><input type=submit></td><tr>
</table>
</form>
</body>
</html>
I would make sure it's not going against the TOS agreement.
As far as the other thing "random events" i have no clue what you are asking.
[/COLOR]