abeisgreat Posted November 29, 2007 Share Posted November 29, 2007 Ok im trying to make a real simple login script. This is what i have so far. 1) a script that posts the username and pass you enter. 2) this script in login.php: <?php $post_user = $_POST['username']; $post_pass = $_POST['password']; $userFile = ($post_user . '.php'); list($passmd5); if ( md5 ($post_pass) == $passmd5 ) { echo "Logged In" }else{ echo "Not Logged In" } echo "Test" ?> 3) a file named like... dream.php (dream being the username) and the file contains: <?php die ('You may not access this file.'); ?> 54c280558263a67e0a84ba34f625c464 so a die command than a MD5 of the users password. When i try this code nothing happens. Any help please? Quote Link to comment https://forums.phpfreaks.com/topic/79484-solved-help-with-loading-data-from-a-txt/ Share on other sites More sharing options...
Wes1890 Posted November 29, 2007 Share Posted November 29, 2007 Where is the form where the user inputs their username and password? Quote Link to comment https://forums.phpfreaks.com/topic/79484-solved-help-with-loading-data-from-a-txt/#findComment-402497 Share on other sites More sharing options...
abeisgreat Posted November 29, 2007 Author Share Posted November 29, 2007 Thats on a separate page. Here what index.html is: <div id="login"> <font size="1"> <form action="login.php" method="post"> Username: <input type="text" name="username" /> Password: <input type="password" name="password" /> <input type="submit" value="Login"/> </form> </font> Quote Link to comment https://forums.phpfreaks.com/topic/79484-solved-help-with-loading-data-from-a-txt/#findComment-402500 Share on other sites More sharing options...
kenrbnsn Posted November 30, 2007 Share Posted November 30, 2007 Where are you reading the file with the password. I don't see any file operations in your script. Ken Quote Link to comment https://forums.phpfreaks.com/topic/79484-solved-help-with-loading-data-from-a-txt/#findComment-402505 Share on other sites More sharing options...
abeisgreat Posted November 30, 2007 Author Share Posted November 30, 2007 Its supposed to load the username and pass from index.html that the user submitted. Then login.php loads $username.php and in that file is the pass Quote Link to comment https://forums.phpfreaks.com/topic/79484-solved-help-with-loading-data-from-a-txt/#findComment-402508 Share on other sites More sharing options...
kenrbnsn Posted November 30, 2007 Share Posted November 30, 2007 You have this statement <php list($passmd5); ?> that doesn't make a whole lot of sense. Where is the variable $passmd5 set? You set the variable $userFile to string containing the filename, but you never do anything with it. Ken Quote Link to comment https://forums.phpfreaks.com/topic/79484-solved-help-with-loading-data-from-a-txt/#findComment-402512 Share on other sites More sharing options...
abeisgreat Posted November 30, 2007 Author Share Posted November 30, 2007 Ya.. I have never done php before so i was trying to get something to work so apparently in my attempt for anything I must have really screwed up that code. So that could be a big problem in my code. I know $userFile needs to get loaded then $passmd5 is the second line in the $userfile But i havnt the slightest idea how to do that Quote Link to comment https://forums.phpfreaks.com/topic/79484-solved-help-with-loading-data-from-a-txt/#findComment-402514 Share on other sites More sharing options...
kenrbnsn Posted November 30, 2007 Share Posted November 30, 2007 The simplest way of doing what you want is: <?php $post_user = stripslashes($_POST['username']); $post_pass = stripslashes($_POST['password']); $userFile = $post_user . '.php'; if (file_exists($userFile)) { list($dmy,$passmd5) = file($userFile); $passmd5 = trim($passmd5); if ( md5 ($post_pass) == $passmd5 ) echo "Logged In"; else echo "Not Logged In"; } else echo "Not Logged In"; echo "Test" ?> Note: code not checked for syntax errors. Ken Quote Link to comment https://forums.phpfreaks.com/topic/79484-solved-help-with-loading-data-from-a-txt/#findComment-402522 Share on other sites More sharing options...
abeisgreat Posted November 30, 2007 Author Share Posted November 30, 2007 Aww thank you it works perfect. I am in your debt Quote Link to comment https://forums.phpfreaks.com/topic/79484-solved-help-with-loading-data-from-a-txt/#findComment-402658 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.