TheJoey Posted August 31, 2009 Share Posted August 31, 2009 Here is my code so far <?php $email = $_POST['email']; $fname = $_POST['fname']; $lname = $_POST['lname']; $age = $_POST['age']; $address = $_POST['address']; $city = $_POST['city']; $fp = fopen("data.txt","a"); if(!$fp) { echo 'Error: Cannot open file.'; exit; } fwrite($fp, $email."||".$fname."||".$lname."||".$age."||".$address."||".$city."\r\n"); fclose($fp); ?> im having real trouble reclaiming that text for a login script. Could anyone start me off. Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/ Share on other sites More sharing options...
wildteen88 Posted August 31, 2009 Share Posted August 31, 2009 Storing logins in text files is not recommended. It is very insecure. You are better of using a database. Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/#findComment-909695 Share on other sites More sharing options...
TheJoey Posted August 31, 2009 Author Share Posted August 31, 2009 Cant use a database because of database restrictions something i should of checked before i paid for it. Is there a way to do it? Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/#findComment-909697 Share on other sites More sharing options...
TheJoey Posted August 31, 2009 Author Share Posted August 31, 2009 <?php readfile("data.txt"); ?> is to read the file althought it reads it with | inbetween everything. But how do i make that information passible between scripts etc Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/#findComment-909707 Share on other sites More sharing options...
wildteen88 Posted August 31, 2009 Share Posted August 31, 2009 I'd use file instead. file returns an array of lines. Then you can use a loop to easily check each line. $lines = file('data.txt'); foreach($lines as $line) { $bits = explode('||', $line); echo '<pre>'.print_r($bits, true).'</pre>'; } Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/#findComment-909710 Share on other sites More sharing options...
TheJoey Posted August 31, 2009 Author Share Posted August 31, 2009 Wow huge help. Thank you. say i wanted every [0] to be user name would that be possible? Array ( [0] => @ [1] => joe [2] => joe [3] => 124 [4] => joe [5] => joe ) Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/#findComment-909713 Share on other sites More sharing options...
wildteen88 Posted August 31, 2009 Share Posted August 31, 2009 ??? Post your question more clearly. Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/#findComment-909718 Share on other sites More sharing options...
TheJoey Posted August 31, 2009 Author Share Posted August 31, 2009 well i was thinking of going to make everyone [0] a username and [1] a password from my stored information. How would i go about doing so? Array ( [0] => joe@joe [1] => joe [2] => joe [3] => 21 [4] => as [5] => as ) Array ( [0] => joe@joe [1] => joe [2] => joe [3] => 21 [4] => as [5] => as ) so [0] => joe@joe would be my username and [1] =>joe would be my password Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/#findComment-909725 Share on other sites More sharing options...
TheJoey Posted August 31, 2009 Author Share Posted August 31, 2009 <?php $userinfo = file("data.txt"); echo '<table>'; foreach($userinfo as $key => $val) { $data[$key] = explode("||", $val); } for($k = 0; $k < sizeof($userinfo); $k++) { echo '<tr><td>Username:</td><td>'.$data[$k][0].'</td></tr>'; echo '<tr><td>Password:</td><td>'.$data[$k][1].'</td></tr>'; echo '<tr><td colspan=2> </td></tr>'; } echo '</table>'; ?> This is displaying it a little easier to explain i think. Username: joe@joe Password: joe Username: joe@joe Password: joe Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/#findComment-909728 Share on other sites More sharing options...
Garethp Posted August 31, 2009 Share Posted August 31, 2009 Why not just foreach($data as $v) { echo '<tr><td>Username:</td><td>'.$v[0].'</td></tr>'; echo '<tr><td>Password:</td><td>'.$v[1].'</td></tr>'; echo '<tr><td colspan=2> </td></tr>'; } Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/#findComment-909753 Share on other sites More sharing options...
TheJoey Posted August 31, 2009 Author Share Posted August 31, 2009 Effectively its the same isnt it? i still need a way to push this information for a login How would i take the username and use it and take the password and use it Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/#findComment-909761 Share on other sites More sharing options...
Garethp Posted August 31, 2009 Share Posted August 31, 2009 if($d[0] == $Username && $d[1] == $Password) { //Log them in } Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/#findComment-909765 Share on other sites More sharing options...
TheJoey Posted August 31, 2009 Author Share Posted August 31, 2009 Im unsure how i would apply this could you give me a example ill most likely create a form. in html and post it via .php Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/#findComment-909768 Share on other sites More sharing options...
TheJoey Posted August 31, 2009 Author Share Posted August 31, 2009 was thinking something like this for the form. Having trouble using the code you gave me to proccess the login echo '<table> <tr><td>Username<br> <form action="read3.php" method="post"> <input name="username" type="text"></td></tr> <tr><td>Password<br> <input name="password" type="password"></td></tr> <tr><td><input value="Submit" type="submit"></td></tr> <tr><td><a href="register/index.php">Register</a></td></tr> </table>'; Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/#findComment-909773 Share on other sites More sharing options...
TheJoey Posted September 1, 2009 Author Share Posted September 1, 2009 was thinking something like this for the form. Having trouble using the code you gave me to proccess the login echo '<table> <tr><td>Username<br> <form action="read3.php" method="post"> <input name="username" type="text"></td></tr> <tr><td>Password<br> <input name="password" type="password"></td></tr> <tr><td><input value="Submit" type="submit"></td></tr> <tr><td><a href="register/index.php">Register</a></td></tr> </table>'; Quote Link to comment https://forums.phpfreaks.com/topic/172568-recall-stored-data-for-login/#findComment-909979 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.