nosmas Posted June 10, 2009 Share Posted June 10, 2009 hello friends I was working on a login form and I used header() function for working, but it ain't redirecting.It is just showing an empty(white) page. _____________________________________________ here is the php code _______________________________________________ <?php //login.php include('includes/db.php'); include('includes/session.php'); $user_id=$_POST['user_id']; $password=md5($_POST['password']);//crypt the password b/c the pwd in db is crypted $query1="SELECT *FROM user WHERE user_id='$user_id' AND user_password='$password'"; $result1=mysql_query($query1) or die(mysql_error()); if(mysql_num_rows($result1)>0){//check if the user exists in the user table setUserSession($user_id,$password); header("Location:user.php?SID"); exit(0); }else{ $query2="SELECT *FROM admin WHERE user_id='$user_id' AND password='$password'"; $result2=mysql_query($query2) or die(mysql_error()); die(mysql_num_rows($result2)); if(mysql_num_rows($result2)>0){//check if the user exists in the admin table setAdminSession($user_id,$password); header("Location:admin.php?SID"); exit(0); }else{ $msg="wrong username or password"; header("Location:login1.php?msg=$msg"); exit(0); } } ?> __________________________________________________ here is the login form ___________________________________________________ <? if(isset($_GET['msg']) && !empty($_GET['msg'])){ echo "<font color=\"red\" >$msg</fornt>"; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> </head> <body> <form action="login.php" method="post"> <pre> <fieldset> user ID<input type="text" name="user_id" maxlength="10" /><br /> Password<input type="password" name="password" maxlength="12" /><br /> <input type="submit" value="login" /> </fieldset> </pre> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/161724-header-function-not-redirecting/ Share on other sites More sharing options...
flyhoney Posted June 10, 2009 Share Posted June 10, 2009 You can only call the header() function if you have not previously output ANYTHING. I.e. this will NOT work: echo 'hi'; header("Location: index.php"); Make sure you have these lines at the top of your script to catch any errors: <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?> Link to comment https://forums.phpfreaks.com/topic/161724-header-function-not-redirecting/#findComment-853304 Share on other sites More sharing options...
nosmas Posted June 10, 2009 Author Share Posted June 10, 2009 But I didn't use any statement that displays any thing AND I posted those two error reporting lines you provided me but it is still the same Link to comment https://forums.phpfreaks.com/topic/161724-header-function-not-redirecting/#findComment-853341 Share on other sites More sharing options...
justAnoob Posted June 10, 2009 Share Posted June 10, 2009 I always do it this way also.... <?php header("Location: http://www.yoursite.com/yourpage.php"); ?> Link to comment https://forums.phpfreaks.com/topic/161724-header-function-not-redirecting/#findComment-853343 Share on other sites More sharing options...
jeff5656 Posted June 10, 2009 Share Posted June 10, 2009 This header thing is real headache - and its so common it has it's own sticky. I wish php would invent a term for redirecting to another url (like javascript does) to avoid this header - output headache! Link to comment https://forums.phpfreaks.com/topic/161724-header-function-not-redirecting/#findComment-853357 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.