PHPBuilder - A Login Script



RSS Twitter
Snippets Other

A Login Script

by: Steven Chalker
|
January 5, 2002

Version: 0.2

Type: Sample Code (HOWTO)

Category: Other

License: GNU General Public License

Description: This login script features Logging in (of course :-)) No Databases 2 Files Tells if logged in registers/unregisters people logging out. My Website is http://stevenchalker.net and my email is steve@stevenchalker.net if any errors occur.



<!-- Updated -->

<!-- Logging in to somewhere .. one file! -->
<!-- Below is the example. -->
<!-- One more thing, it will create "logged.txt" -->
<!-- so it can store users and passwords. -->

<?php
function login_connect($username,$password) {
$content = join('',file("logged.txt"));
if(ereg($username.":".$password." | ",$content)) {
$fp=fopen("logged.txt","a+");
$readr = fread($fp,filesize("logged.txt"));
$readr = str_replace("$username $password | ","$username $password loggedin | ",$readr);
fwrite($fp,$readr);
fclose($fp);
return true;
} else {
return false;
}
}
function login_isconnected($thelogin,$username,$password) {
$fileF = file("logged.txt");
$content = join('',$fileF);
if(ereg("$username $password loggedin | ",$content)) {
return true;
} else {
return false;
}
}
function login_register($username,$password) {
$fp=fopen("logged.txt","a+") or return false; // Is the file registered/At Writable?
if(fwrite($fp,"$username $password | ")) {
return true;
}
fclose($fp);
}
function login_unregister($username,$password) {
$fp=fopen("logged.txt","a+");
$readed = fread($fp,filesize("logged.txt"));
$readed = str_replace("$username $password | ","",$readed);
fwrite($fp,$readed);
fclose($fp);
}
function login_quit($username,$password) {
  $fp=fopen("logged.txt","a+");
$re = fread($fp,filesize("logged.txt"));
$re = str_replace("$username $password loggedin | ","$username $password | ",$re);
      fwrite($fp,$re);
      fclose($fp);
}
// -------------------- Example --------------------------
login_register("lentin64","test"); // Let it put in to the 2nd file
$logged = login_connect("lentin64","test")
if(login_isconnected("lentin64","test")) {
echo "Logged in";
} else {
echo "Not Logged in";
}
login_quit("lentin64","test"); // Logout
login_unregister("lentin64","test"); // Get rid of him
?>

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Steven Chalker

Comment:



Comment:

(Maximum characters: 1200). You have characters left.