ztealmax Posted December 5, 2006 Share Posted December 5, 2006 Hi is it possible to change this code to use text file instead of a sql database? ;)just an idea, but think it should work?[b]Login.php[/b][code]<?session_start(); // start session.?><!-- header tags, edit to match your own, or include template header file. --><html><head><title>Login</title><head><body><?if(!isset($username) | !isset($password)) {// escape from php mode.?><form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST"><p align="center">Members only. Please login to access this document.</p><table align="center" border="0"> <tr> <th>Username: </th> <th><input type="text" name="username"> </th> </tr> <tr> <th>Password: </th> <th><input type="password" name="password"> </th> </tr> <tr> <th colspan="2" align="right"><input type="submit" value="Login"></form> </th> </tr></table></body></html><?exit();}// If all is well so far.session_register("username");session_register("password"); // register username and password as session variables.// Here you would check the supplied username and password against your database to see if they exist.// For example, a MySQL Query, your method may differ.$sql = mysql_query("SELECT password FROM user_table WHERE username = '$username'");$fetch_em = mysql_fetch_array($sql);$numrows = mysql_num_rows($sql);if($numrows != "0" & $password == $fetch_em["password"]) {$valid_user = 1;}else {$valid_user = 0;}// If the username exists and pass is correct, don't pop up the login code again.// If info can't be found or verified....if (!($valid_user)){session_unset(); // Unset session variables.session_destroy(); // End Session we created earlier.// escape from php mode.?><form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST"><p align="center">Incorrect login information, please try again. You must login to access this document.</p><table align="center" border="0"> <tr> <th>Username: </th> <th><input type="text" name="username"> </th> </tr> <tr> <th>Password: </th> <th><input type="password" name="password"> </th> </tr> <tr> <th colspan="2" align="right"><input type="submit" value="Login"></form> </th> </tr></table></body></html><?exit();}?>[/code]//CheersMartin Link to comment https://forums.phpfreaks.com/topic/29471-remake-a-script-to-use-a-text-file-instead-of-mysql/ Share on other sites More sharing options...
fert Posted December 5, 2006 Share Posted December 5, 2006 it is possible, but it would be kind of difficult Link to comment https://forums.phpfreaks.com/topic/29471-remake-a-script-to-use-a-text-file-instead-of-mysql/#findComment-135259 Share on other sites More sharing options...
ztealmax Posted December 5, 2006 Author Share Posted December 5, 2006 ok :)thanx Link to comment https://forums.phpfreaks.com/topic/29471-remake-a-script-to-use-a-text-file-instead-of-mysql/#findComment-135260 Share on other sites More sharing options...
keeB Posted December 5, 2006 Share Posted December 5, 2006 To be honest... not too difficult.Here's a mockup of how I would do it, probably with OO, though[code]<?php/** * @author: keeb * @description: Parses a text file with "<username>:<password>" format. Password should be stored in md5. */ $userlist = "userlist.txt"; //path to the list of users$password_to_check = md5("abc123"); // mock user input$user_to_check = "keeb"; //mock user input$handle = fopen($userlist, "r");$contents = fread($handle, filesize($userlist));$contents = explode("\n", $contents); //turn contents in to array seperated by spaces;foreach($contents as $check) { if ( returnUser($check) == $user_to_check && returnPassword($check) == $password_to_check ) { print "user logged in"; }}function returnUser($str) { $data = explode(":", $str); return $data[0];}function returnPassword($str) { $data = explode(":", $str); return $data[1];}?>[/code]My sample userlist.txt looks like this:[code]keeb:e99a18c428cb38d5f260853678922e03[/code]Good luck Link to comment https://forums.phpfreaks.com/topic/29471-remake-a-script-to-use-a-text-file-instead-of-mysql/#findComment-135301 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.