iSelfSchooling.com  Since 1999     References  |  Search more  | Oracle Syntax  | Free Online Oracle Training

    Home      .Services     Login       Start Learning     Certification      .                 .Share your BELIEF(s)...

 

. Online Accounting        .Copyright & User Agreement   |
    .Vision      .Biography     .Acknowledgement

.Contact Us      .Comments/Suggestions       Email2aFriend    |

 

How to read a file incrementally in PHP?

How to read a file incrementally in PHP?


Let us read a password file to verify a user. If the user is not register, then reject the login process. Let us call this script “verifiylogin.php.” Let us assume that the password file calls “passwordfile.txt.” The passwordfile.txt file contains username and password separated by tab. A user enters his/her username and password. The script checks to make sure that the user’s password is a valid password. 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitionl.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Verify a user name login</title>
</head>

<body>

<?php 
// Error handling.
ini_set(‘display_errors’,1);
error_reporting (E_ALL & ~E_NOTICE);

if (isset ($_POST[‘submit’])) { // check the form was submitted.
$logflag = FALSE;
$fp = fopen (‘../passwordfile.txt’,’rb’);
while ($line = fgetcsv ($fp,100,”\t”)) { // read the first 100 character or one line with tab delimiter
if (($line[0] == $_POST[‘username’]) AND ($line[1] == crypt ($_POST[‘userpassword’],$line[1])){
// notice that you use the crypt() function to check the submitted password against
// its encrypted version in the password file. 
// now we found the match, change the logflag.
$lagflag = TRUE;
break;
}
}

fclose ($fp);
if ($logfile) {
// call my secret php file.
getsecret.php;
} else {
print ‘<p>The username and password do not match, please re-enter them.</p>’;
}

} else { // re-enter the password.
?>
<form action=”verifylogin.php” method=”post”>
User Name: <input type=”text” name=”username” size=”20” /><br /><br />
<input type=”submit” name=”submit” value=”Enter user name and password” /><br /><br />
</form>

<?php
} // end of submission 
?>
</body>
</html>

 

 

Google
 
Web web site