jarcoal Posted December 3, 2006 Share Posted December 3, 2006 I'm writing a very simple login system for my blog, and for some reason I can't get this to work. The text file "bloggerinfo.php" contains the correct login/pass on separate lines (hence the file()). But even if I type in the right log/pass, $correct seems to always equal 0 by the end, failing the login. Here is my code so far, thanks for any help:[code]<?php $s_name = $_REQUEST["name"]; $s_pass = $_REQUEST["pass"]; $userpass = file('bloggerinfo.php'); if ($s_name == $userpass[0]) { if ($s_pass == $userpass[1]) { $correct = 1; setcookie("blogger", "1", time()+3600); } else { $correct = 0; } } else { $correct = 0; } fclose($userpass);?><html><body><?php if ($correct == 1) { echo "Successful login. Return to <a href=blog.php>main page</a>."; } else { echo "Incorrect login. Return to <a href=login.php>login page</a>."; }?></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/29340-login-trouble-comparing-strings-to-array-elements/ Share on other sites More sharing options...
keeB Posted December 3, 2006 Share Posted December 3, 2006 Hello,Can I get an example of what the bloggerinfo.php may look like? Link to comment https://forums.phpfreaks.com/topic/29340-login-trouble-comparing-strings-to-array-elements/#findComment-134532 Share on other sites More sharing options...
jarcoal Posted December 3, 2006 Author Share Posted December 3, 2006 it's a file that's built by a script for creating users.here's that code:[code]$name = $_REQUEST["name"];$pass = $_REQUEST["pass"];$email = $_REQUEST["email"]; $bloggerinfo = fopen('bloggerinfo.php', 'a');fwrite($bloggerinfo, $name. "\n" . $pass . "\n" . $email );fclose($bloggerinfo);[/code]so as you can see it just assembles a file with the username on line one, password on line two, email address on line three. Link to comment https://forums.phpfreaks.com/topic/29340-login-trouble-comparing-strings-to-array-elements/#findComment-134536 Share on other sites More sharing options...
jarcoal Posted December 4, 2006 Author Share Posted December 4, 2006 bump Link to comment https://forums.phpfreaks.com/topic/29340-login-trouble-comparing-strings-to-array-elements/#findComment-134704 Share on other sites More sharing options...
trq Posted December 4, 2006 Share Posted December 4, 2006 You might try....[code=php:0]if ($s_name."\n" == $userpass[0])[/code] Link to comment https://forums.phpfreaks.com/topic/29340-login-trouble-comparing-strings-to-array-elements/#findComment-134705 Share on other sites More sharing options...
jarcoal Posted December 4, 2006 Author Share Posted December 4, 2006 it worked!!many many thanks! Link to comment https://forums.phpfreaks.com/topic/29340-login-trouble-comparing-strings-to-array-elements/#findComment-135102 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.