SUNIL16 Posted February 21, 2009 Share Posted February 21, 2009 Hi Friends Below is my code for login authentication if ($_POST['Submit']=='Login') { $username = mysql_real_escape_string($_POST['uname']); $md5pass = md5($_POST['password']); $sql = "SELECT usersid,username FROM users WHERE username = '$username' AND password = '$md5pass' AND user_activated='1'"; $result = mysql_query($sql) or die (mysql_error()); $num = mysql_num_rows($result); if ( $num != 0 ) { // A matching row was found - the user is authenticated. session_start(); list($user_id,$usernamel) = mysql_fetch_row($result); // this sets variables in the session $_SESSION['user']= $username; if (isset($_GET['ret']) && !empty($_GET['ret'])) { header("Location: $_GET[ret]"); } else { header("Location: http://www.xyz.com/myaccount.php"); } //echo "Logged in..."; exit(); } header("Location: login.php?msg=Invalid Login"); echo "Error:"; exit(); } I am not getting redirect to myaccount.php using header function. please help.. any header functions are not functioning in my pages.. Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/ Share on other sites More sharing options...
GingerRobot Posted February 21, 2009 Share Posted February 21, 2009 So what does happen? Are you sure that you named your submit button with a capital S and the value with a capital L? I ask since none of your other varaiables/array indexes are using capitals... Do you have error_reporting set to E_ALL and display_errors turned on? Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-767899 Share on other sites More sharing options...
angelcool Posted February 21, 2009 Share Posted February 21, 2009 I just tried: <?php if (true) { $username = mysql_real_escape_string($_POST['uname']); $md5pass = md5($_POST['password']); $sql = "SELECT usersid,username FROM users WHERE username = '$username' AND password = '$md5pass' AND user_activated='1'"; //$result = mysql_query($sql) or die (mysql_error()); //$num = mysql_num_rows($result); if ( true ) { // A matching row was found - the user is authenticated. session_start(); list($user_id,$usernamel) = mysql_fetch_row($result); // this sets variables in the session $_SESSION['user']= $username; if (isset($_GET['ret']) && !empty($_GET['ret'])) { header("Location: $_GET[ret]"); } else { header("Location: http://www.yahoo.com"); } //echo "Logged in..."; exit(); } header("Location: http://google.com"); echo "Error:"; exit(); } ?> and worked. I was redirected to yahoo.com, and if the second true is changed to false I will get redirected to google.com is $_POST['Submit']=='Login' being set? (does it returns true?) Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-767905 Share on other sites More sharing options...
SUNIL16 Posted February 22, 2009 Author Share Posted February 22, 2009 Thanks for reply to both of you, below is my form code <form name="myform" action="login.php" method="post" onSubmit="return validate()"> <table class="main_txt" border="1" width="100%"> <tr> <td width="595" colspan="2" bgcolor="#BFBFBF" ><font color="#FFFFFF"><b>Login</b></font></td> </tr> <tr> <td width="292" bgcolor="#EBEBEB" >User Name</td> <td width="301" bgcolor="#EBEBEB" > <input type="text" name="uname" size="20" maxlenght="30"></td> </tr> <tr> <td width="292" bgcolor="#EBEBEB" >Password</td> <td width="301" bgcolor="#EBEBEB" > <input type="password" name="password" size="20" maxlenght="10"></td> </tr> <tr> <td width="595" colspan="2" bgcolor="#BFBFBF" height="1"> <input type="Submit" name="Submit" value="Login"> (<a href="forgotpass.html">Forgot password</a>)</td> </tr> </table> </form> I used caps only. and $_POST['Submit']=='Login' is setting but still i am not getting. Is there anything like header should be used at the top of all other code? Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-768283 Share on other sites More sharing options...
angelcool Posted February 22, 2009 Share Posted February 22, 2009 I ran your form, it seems OK. What exactly happens whe you click Login? Nothing? If so,my best shot is that onSubmit="return validate()" in your form opening tag is returning false. Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-768310 Share on other sites More sharing options...
SUNIL16 Posted February 22, 2009 Author Share Posted February 22, 2009 hi its working fine only that is if you echo"logged in" in place header function its showing as logged in. Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-768350 Share on other sites More sharing options...
PFMaBiSmAd Posted February 22, 2009 Share Posted February 22, 2009 Do you have error_reporting set to E_ALL and display_errors turned on? You did not answer that question. About 99.98 percent of the time developing and debugging your code on a system with those two settings the php errors will tell you why a header does not work. Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-768423 Share on other sites More sharing options...
redarrow Posted February 22, 2009 Share Posted February 22, 2009 hi its working fine only that is if you echo"logged in" in place header function its showing as logged in. what you said is write you got a exit; and it will show on a page on it own any think that above the exit function. Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-768428 Share on other sites More sharing options...
SUNIL16 Posted February 22, 2009 Author Share Posted February 22, 2009 Hi Thanks for reply.. i didnt used any thing like error_reporting set to E_ALL and display_errors turned on? i am new to php, i dont know where i have to set(E_ALL) or where it is set.. Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-768467 Share on other sites More sharing options...
SUNIL16 Posted February 22, 2009 Author Share Posted February 22, 2009 Hi Friends, i even tried by giving below code in my php file ini_set(’display_errors’, ‘On’); ini_set(’error_reporting’, E_ALL); But still its not redirecting.... please give any suggestions. i am totally confused. waiting for reply. Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-768559 Share on other sites More sharing options...
SUNIL16 Posted February 23, 2009 Author Share Posted February 23, 2009 any one please get me where i am wrong.... Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-768990 Share on other sites More sharing options...
PFMaBiSmAd Posted February 23, 2009 Share Posted February 23, 2009 Any chance that myaccount.php is redirecting back to login.php? Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-768996 Share on other sites More sharing options...
seany123 Posted February 23, 2009 Share Posted February 23, 2009 try redirecting to a different url, to see what happens. Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-769016 Share on other sites More sharing options...
SUNIL16 Posted February 24, 2009 Author Share Posted February 24, 2009 i given redirection to www.yahoo.com but still its not working. here i am posting the entire code once again. Please look into it and let me know where i went wrong.. <h1 class="h1" align="left"> Login</h1> <?php require "config.php"; if ($_POST['Submit']=='Login') { $username = mysql_real_escape_string($_POST['uname']); $md5pass = md5($_POST['password']); $sql = "SELECT usersid,username FROM users WHERE username = '$username' AND password = '$md5pass' AND user_activated='1'"; $result = mysql_query($sql) or die (mysql_error()); $num = mysql_num_rows($result); if ( $num != 0 ) { // A matching row was found - the user is authenticated. session_start(); list($user_id,$usernamel) = mysql_fetch_row($result); // this sets variables in the session $_SESSION['user']= $username; if (isset($_GET['ret']) && !empty($_GET['ret'])) { header("Location: $_GET[ret]"); } else { header("Location: http://www.yahoo.com"); } //echo "Logged in..."; exit(); } header("Location: login.php?msg=Invalid Login"); echo "Error:"; exit(); } ?> <form name="myform" action="login.php" method="post" > <table class="main_txt" border="1" width="100%"> <tr> <td width="595" colspan="2" bgcolor="#BFBFBF" ><font color="#FFFFFF"><b>Login</b></font></td> </tr> <tr> <td width="292" bgcolor="#EBEBEB" >User Name</td> <td width="301" bgcolor="#EBEBEB" > <input type="text" name="uname" size="20" maxlenght="30"></td> </tr> <tr> <td width="292" bgcolor="#EBEBEB" >Password</td> <td width="301" bgcolor="#EBEBEB" > <input type="password" name="password" size="20" maxlenght="10"></td> </tr> <tr> <td width="595" colspan="2" bgcolor="#BFBFBF" height="1"> <input type="Submit" name="Submit" value="Login"> (<a href="forgot.php">Forgot password</a>)</td> </tr> </table> </form> i am not getting header msg any thing with header function in all my pages. Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-769865 Share on other sites More sharing options...
trq Posted February 24, 2009 Share Posted February 24, 2009 The very first line outputs html to the browser. You cannot output anything to the browser prior to calling header. Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-769871 Share on other sites More sharing options...
PFMaBiSmAd Posted February 24, 2009 Share Posted February 24, 2009 A) You never posted that complete code before, B) You have HTML content being output on line one of that file that prevents the headers from working, C) Wherever you put the lines of code for full php error reporting was not in that file because you would have gotten errors telling you where the HTML content was being output. Link to comment https://forums.phpfreaks.com/topic/146269-page-not-redirecting-using-header/#findComment-769872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.