Baabu Posted February 28, 2008 Share Posted February 28, 2008 Hello every one , <? include ("db.php"); if(authenticateUser($username,$upass)) { setcookie("cookie_passwd",$upass); setcookie("cookie_user",$uname); //echo "cookie set"; header("Location:Http://localhost/cart/list.php"); exit; } else { //echo "un"; header("Location:http://localhost/cart/index.php"); exit(); } ?> in the above code everything is working fine even it displays cookie set(which is for just checking) when i a put a comment on the echo statement the page just goes blank and no redirect. Can anyone help me out !!! ??? Best Regards Baabu Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 If you echo ANYTHING to the browser (even a space) before the location header, the header will fail and you aren't forwarded anywhere. This is what is happening to you. You must have error reporting turned off, or you would have an error telling you about this problem. Quote Link to comment Share on other sites More sharing options...
Baabu Posted February 28, 2008 Author Share Posted February 28, 2008 well here are both the code <? $dbserver="localhost"; $dbadmin="ar"; $pass="pass"; $dbname="cart"; function authenticateUser($user,$upass) { global $dbserver,$dbadmin,$pass,$dbname; $cxn=connectToDb($dbserver,$dbadmin,$pass,$dbname); $query="Select * from users where username='$user' and upass='$upass'"; $result=mysql_query($query); if(($row=mysql_fetch_array($result))) { if($upass==$row['upass'] && upass!="") { return 1; } else return 0; } } function connectToDb($server,$user,$pass,$database) { $s=mysql_connect($server,$user,$pass); $d=mysql_select_db($database,$s); if(!$s || !$d) return false; else return true; } function GetCartId() { if(isset($_COOKIE["cartId"])) { return $_COOKIE["cartId"]; } else { session_start(); setcookie("cartId", session_id(), time+((3600 * 24) * 30)); return session_id(); } } ?> this is db.php and then login.php <? include ("db.php"); if(authenticateUser($username,$upass)) { setcookie("cookie_passwd",$upass); setcookie("cookie_user",$uname); header("Location:Http://localhost/cart/list.php"); exit; } else { header("Location:http://localhost/cart/index.php"); exit(); } ?> Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 I'm not too clear on exactly what your problem is, but I see a few things you need to fix: 1) Don't use: <? for an opening tag, use: <?php The first one can cause problems sometimes, as browsers will sometimes parse it as XML instead of PHP, depending on your settings. 2) You are passing $username and $upass to the function authenticateuser, but you haven't set those variables anywhere. 3) You are storing the user's password in a cookie. VERY dangerous - anyone who uses that computer can go in and see the users password quickly and easily. You shouldn't do this. As I said, I don't really understand your problem. But I kind of suspect that its #2 of my list. Quote Link to comment Share on other sites More sharing options...
Baabu Posted February 28, 2008 Author Share Posted February 28, 2008 well those are passed from the login page which is just the html file whose code is as follows <html> <head> <title>Test Page</title> </head> <body> <table width="100%" height="2"> <tr><td><font size="-2">Login Page</font></td></tr> </table> <form action="login.php" method="post"> Login Name: <input type="text" name="username"> Password: <input type="password" name="upass"> <input type="submit" value="Login"> </form> </body> </html> the problem is that page is not redirecting... Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 $username and $upass don't exist - you haven't set them anywhere. Your code is not redirecting because you are passing empty values into authenticateuser. Change your code so it says this: if(authenticateUser($_POST['username'],$_POST['upass'])) Quote Link to comment Share on other sites More sharing options...
Baabu Posted February 28, 2008 Author Share Posted February 28, 2008 well i did that but nothing happend even if i try to echo their values before setcookie() the values are printed 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.