Add a sign-up feature to a flat file login script


Posted on 16th Feb 2014 07:03 pm by admin

I'm working on a flat file login script and I would like to add a sign-up feature to it with a email confirmation process.

Here is my code :

Line number On/Off | Expand/Contract <?php//sessions must be initialized prior to any output if output buffering if offsession_start(); //the list of files containing passwords$files = array( "pass.txt", "test/pass2.txt", "admin/pass3.txt"); //if list of users not set create a new arrayif(!isset($_SESSION['users'])) $_SESSION['users'] = array(); if(isset($_POST['username']) && isset($_POST['password'])){ //need to remove slashes from POST if magic_quotes are on if(get_magic_quotes_gpc()){ $_POST['username'] = stripslashes($_POST['username']); $_POST['password'] = stripslashes($_POST['password']); } $userFound = false; //we need this to exit the loops foreach($files as $file){ //loop every file in the $files array if($fh = fopen($file, "r")){ while(!feof($fh) && !$userFound){ //while not the end of the current file or the user was not found list($username, $password, $url) = explode(",", fgets($fh,1024)); if(($username == $_POST['username']) && ($password = $_POST['password'])){ $_SESSION['username'] = $username; $_SESSION['present'] = true; $_SESSION['legal'] = true; $_SESSION['profile'] = $username.".txt"; array_push($_SESSION['users'], $username); //add the current user to the list of users header("Location: ".$url); $userFound = true; //confirm that the user was found } } fclose($fh); //we need to use break to exit the foreach loop if the user is found in one of the files if($userFound) break; } else echo "Unable to complete"; } if(!$userFound) login('Invalid Member name or Password.<br />');} else { login();}?><?php function login($response='Welcome visitor !') {?>

the user, password and redirection path are listed like the following in the files :

user, pass, path
user, pass, path

How can I add this sign in feature, user would click on sign in, fill a form with his/her full name as user, no space, choose a password, an email would be send and there would be an link to confirm, then the user would be added to the really list.


Thanks!

116 Like 26 Dislike
Previous php-forum Next php-forum
Other php-forum

matching numbers inside ( )
I know I can match numbers by just [0-9]+, so I thought matching numbers inside ( ) would be somethi

PHP mail() with images
I'm trying to get images to send along with my HTML e-mail sent through PHP mail(). I only tried vie

Include with Parameters
In a particular page I would like to include a file that requires $_GET parameters.

when I go

multipart emiail forms
Hi All,

I am new to the boards and I've been working on a form (which is rather massive, imo

preg_match logical error
Code: <?php
$s = file_get_contents("page.html");
preg_match('/<div cla

Motivational Posters
Hello,

I wonder how can i do them in php. Are there any sample codes that you can show me?

Creating an invoice
Using fpdf I am trying to create an invoice to send to clients. The products are sold in pricing tie

PHP template help
Ok, I don't know if anyone can help me but I am using PHP templates to make a site. I am a newbie an

PHP MySQL and DATE
Hi everyone

I have a databse and in one of the columns I have date values such as 2009-March-

Which PHP-Editor do you think is the best?
Hi everyone,
Myself Brian Anderson. For the last 2 years i have been working a

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash