HmmZ 0 Report post Posted June 25, 2005 I'm having troubles with my authentication function, if the the users uses wrong login info, it works like a charm, but it gives me errors when i set the cookies, so help would be appreciated... Function auth(){$user=$_POST['username'];$pass=$_POST['password'];$qry="SELECT id from Solarity where username='$user' and password='$pass'";$result=mysql_query($qry) or die("A problem occured during authentication process");$rows=mysql_num_rows($result);if($rows<=0){print "<font class=\"content\">Wrong username and/or password<br>";print "$user | $pass<br>";print "<a href=\"javascript:history.go(-1)\"><b>Go Back</b></a></font>";exit;} elseif($rows=1) {setcookie("logged", "TRUE", time()+(900*1));setcookie("username", "$user");print "<font class=\"content\">Successfully logged in $user<br>";print "<a href=\"index.php?fid=area\">Continue to Admin Area</a></font>";}} By the way, the headers errors kicked in when i inserted the font classes (to give a cleaner display >.> . I hope it isn't the problem.. Share this post Link to post Share on other sites
truefusion 3 Report post Posted June 26, 2005 I'd have to say it's because you used the "elseif" function, but i could be wrong. It might work if you change it to just "else". Share this post Link to post Share on other sites
TimothyA 0 Report post Posted June 26, 2005 cookies are evil! use sessions and as for the code...you got it reversed....use the if {} else {} magic dude! the if statement ought to be the "correct user/pass" routine and else should be if the user/pass is wrong... but that's just my 50 dollars.If you're really desperate you can use my code as a guide if (mysql_num_rows($result) == 1) { // the user id and password match, // set the session $_SESSION['user_is_logged_in'] = true; // after login we move to the main page echo '<meta http-equiv="refresh" content="1;url=/members/index.php">'; echo "<div align=\"center\">Welcome back $userId, you are being directed to the members page.</div>"; exit; } else { $errorMessage = 'Sorry, wrong user id / password'; } Share this post Link to post Share on other sites
HmmZ 0 Report post Posted June 26, 2005 My god, I am soooooo smart >.> I first had the full script in index.php, after seeing the lots kb it would gonna have eventually (function bases structure) i decided to make a main.php and include it in my index.php...after that...i decided to put header stuff and footer stuff in separate files and include it aswell (leaving 85bytes on index.php You can guess...the output started at "header.php:8" to be more precise, I had the following: index.php <?phpinclude("config.php");include("header.php");require_once("main.php");include("footer.php");?> main.php <?phpsession_start;include("config.php"); as you can see, while the header include in index.php comes BEFORE the include of main.php, it already has send headers, so the only thing i actually had to do was take off the header.php include in index.php and do the include in main.php index.php <?phpinclude("config.php");require_once("main.php");include("footer.php");?> main.php <?phpsession_start;include("header.php");include("config.php"); and that works, no header errors anymore I hope that all made any sense, lotsa followups per line Share this post Link to post Share on other sites
beeseven 0 Report post Posted June 27, 2005 A little something I noticed: You have "elseif($rows=1)," but it should be "elseif($rows==1)," because the first would be like "if the value 1 is assigned to $rows" as opposed to "if the value of $rows is 1." Share this post Link to post Share on other sites
HmmZ 0 Report post Posted June 27, 2005 Thanks for the additional comment beeseven , ill keep it in mind for next time Share this post Link to post Share on other sites