TheJoey Posted September 1, 2009 Share Posted September 1, 2009 Im stuck making this login script. Ive done storing the users on a flat file. Then it recalls only the needed information. But just then im stuck how do i use the information for a login script Can i use $_POST? <?php $userinfo = file("data.txt"); echo '<table>'; foreach($userinfo as $key => $val) { $data[$key] = explode("||", $val); } for($k = 0; $k < sizeof($userinfo); $k++); } ?> Someone suggested if($d[0] == $username && $d[1] == $password) { echo'Loggin successfull' ; Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted September 1, 2009 Share Posted September 1, 2009 yes. Make a HTML form, POST that information to your PHP script, use $_POST to check whether the details entered match any records in your flat file database. Then redirect the user to where ever. http://www.w3schools.com/php/php_post.asp Quote Link to comment Share on other sites More sharing options...
TheJoey Posted September 1, 2009 Author Share Posted September 1, 2009 The only problem is i dont know where to start. How do i give variable to my information if it is being retreieved from a .txt file? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted September 1, 2009 Share Posted September 1, 2009 reading file contents... http://www.tizag.com/phpT/fileread.php The rest is up to you to learn. We can only point you in the right direction. I recommend reading through the PHP tutorials on tizag.com, If anything doesn't make sense look it up on php.net There is some fine examples of how to do various tasks in PHP on the PHP Freaks website. Good Luck Quote Link to comment Share on other sites More sharing options...
TheJoey Posted September 1, 2009 Author Share Posted September 1, 2009 Thanks ill give it a go Quote Link to comment Share on other sites More sharing options...
TheJoey Posted September 1, 2009 Author Share Posted September 1, 2009 i found no tutirouls that help produce a $_POST from a text file Quote Link to comment Share on other sites More sharing options...
trq Posted September 1, 2009 Share Posted September 1, 2009 i found no tutirouls that help produce a $_POST from a text file You don't need to add anything to the $_POST array from a text file. Quote Link to comment Share on other sites More sharing options...
TheJoey Posted September 1, 2009 Author Share Posted September 1, 2009 how do i much the login input to that on the data.txt Quote Link to comment Share on other sites More sharing options...
trq Posted September 1, 2009 Share Posted September 1, 2009 As an example. Username and password combos are stored in a file. foo:bar bob:whatever bruce:youok Get you users submitted username and password. $username = $_POST['username']; $password = $_POST['password']; Now check them against the entires in the file. session_start(); $handle = fopen("users.txt", "r"); $valid = false; while ($userinfo = fscanf($handle, "%s:%s\n")) { list ($name, $pass) = $userinfo; if ($username == $name && $password == $pass) { $valid = true; } } fclose($handle); if ($valid) { $_SESSION['logged_in'] = true; } ?> Quote Link to comment Share on other sites More sharing options...
TheJoey Posted September 1, 2009 Author Share Posted September 1, 2009 while ($userinfo = fscanf($handle, "%s:%s\n")) { list ($name, $pass) = $userinfo; if ($username == $name && $password == $pass) { $valid = true; } could you explain what %s:%s\n does? thanks for the example Quote Link to comment Share on other sites More sharing options...
TheJoey Posted September 1, 2009 Author Share Posted September 1, 2009 <?php session_start(); $handle = fopen("users.txt", "r"); $valid = false; while ($userinfo = fscanf($handle, "%s:%s\n")) { list ($name, $pass) = $userinfo; if ($username == $name && $password == $pass) { $valid = true; } } fclose($handle); if ($valid) { $_SESSION['logged_in'] = true; echo 'yay ur in'; } else { echo 'You entered a wrong password'; } ?> i added a echo just to test it seems im always entering a wrong password. Quote Link to comment Share on other sites More sharing options...
TheJoey Posted September 2, 2009 Author Share Posted September 2, 2009 <?php session_start(); $handle = fopen("users.txt", "r"); $valid = false; while ($userinfo = fscanf($handle, "%s:%s\n")) { list ($name, $pass) = $userinfo; if ($username == $name && $password == $pass) { $valid = true; } } fclose($handle); if ($valid) { $_SESSION['logged_in'] = true; echo 'yay ur in'; } else { echo 'You entered a wrong password'; } ?> i added a echo just to test it seems im always entering a wrong password. Quote Link to comment 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.