Jump to content
xisto Community
Sign in to follow this  
HmmZ

Problem With Headers setcookie errors

Recommended Posts

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

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

cookies are evil! use sessions :rolleyes:

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 :lol:

   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

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 :lol:

 

I hope that all made any sense, lotsa followups per line :rolleyes:

Share this post


Link to post
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.