djw821 Posted March 8, 2008 Share Posted March 8, 2008 I am trying to redirect from my login script to my members page. I can't seem to do it. I use this code if($row) { header('Location: Members.htm'); exit(); }else{ print '<p><font color = "red" size = "+1">The Username and Password do not match those on file.</font></p>'; If I subsitute the header function for a print function ex if($row{ print '<p>SUCCESS</p>'; It will work so I am pretty sure that $row is correct. But if I use the header function I get a blank white screen no error messages or anything. Can some one help me? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/95096-redirect-issues/ Share on other sites More sharing options...
Daniel0 Posted March 8, 2008 Share Posted March 8, 2008 Do you have display_errors set to on and error_reporting to E_ALL? If not, then you probably won't see the error mentioned here: http://www.phpfreaks.com/forums/index.php/topic,95562.0.html Quote Link to comment https://forums.phpfreaks.com/topic/95096-redirect-issues/#findComment-487120 Share on other sites More sharing options...
djw821 Posted March 8, 2008 Author Share Posted March 8, 2008 I turned my notices on and I got an output buffering error I will work on that and see what happens, Thanks Quote Link to comment https://forums.phpfreaks.com/topic/95096-redirect-issues/#findComment-487137 Share on other sites More sharing options...
djw821 Posted March 8, 2008 Author Share Posted March 8, 2008 I turned on my error reporting and took care of the output buffering issue but still come to a plain white screen. With no errors. Quote Link to comment https://forums.phpfreaks.com/topic/95096-redirect-issues/#findComment-487147 Share on other sites More sharing options...
soycharliente Posted March 8, 2008 Share Posted March 8, 2008 What other code do you have above your header() call? Quote Link to comment https://forums.phpfreaks.com/topic/95096-redirect-issues/#findComment-487156 Share on other sites More sharing options...
djw821 Posted March 8, 2008 Author Share Posted March 8, 2008 Here is the section of code. $query = "SELECT user_id, first_name FROM registration WHERE user_name ='$un' AND password=PASSWORD('$p')"; $result = @mysql_query ($query); $row = mysql_fetch_array ($result, MYSQL_NUM); if($row) { header('Location: Members.htm'); exit(); }else{ print '<p><font color = "red" size = "+1">The Username and Password do not match those on file.</font></p>'; } ob_end_clean(); mysql_close(); Quote Link to comment https://forums.phpfreaks.com/topic/95096-redirect-issues/#findComment-487158 Share on other sites More sharing options...
soycharliente Posted March 8, 2008 Share Posted March 8, 2008 That all looks good to me. Maybe your file isn't Members.htm? Case sensitive? File extension? Try echoing the query to see exactly what it's sending. Maybe it's getting a result, just not the one you want? Quote Link to comment https://forums.phpfreaks.com/topic/95096-redirect-issues/#findComment-487249 Share on other sites More sharing options...
AdamCox9 Posted March 8, 2008 Share Posted March 8, 2008 You have to send out the headers BEFORE displaying anything else even a echo " "; Try using this if you have already displayed output: <META HTTP-EQUIV=\"refresh\" content=\"2; URL=index.php\"> "; Quote Link to comment https://forums.phpfreaks.com/topic/95096-redirect-issues/#findComment-487251 Share on other sites More sharing options...
djw821 Posted March 8, 2008 Author Share Posted March 8, 2008 I got this figured out thanks for all your help Quote Link to comment https://forums.phpfreaks.com/topic/95096-redirect-issues/#findComment-487314 Share on other sites More sharing options...
azfar siddiqui Posted March 9, 2008 Share Posted March 9, 2008 Make sure you are not sending any output to the browser before you are redirecting... it will not redirect.. but it will generate an error.. on the other hand, after redirecting you can do anything you want Quote Link to comment https://forums.phpfreaks.com/topic/95096-redirect-issues/#findComment-487547 Share on other sites More sharing options...
djw821 Posted March 9, 2008 Author Share Posted March 9, 2008 What I was doing worng was this: 1 2<?php ob_start; when I change it to 1<?php ob_start; it worked I just needed to mover the ob_start to the very top of the page even though there was nothing there. Quote Link to comment https://forums.phpfreaks.com/topic/95096-redirect-issues/#findComment-487656 Share on other sites More sharing options...
Xajel Posted March 9, 2008 Share Posted March 9, 2008 What I was doing worng was this: 1 2<?php ob_start; when I change it to 1<?php ob_start; it worked I just needed to mover the ob_start to the very top of the page even though there was nothing there. that's nothing there is a thing in php, that's a linebreak and this is output so the header wont work in case of header or cookies, no output must be sent before the header or cookies, wether its an echo, a line break or what ever... in your case, starting at the secod line is equals to echo "\n"; so the page has output Quote Link to comment https://forums.phpfreaks.com/topic/95096-redirect-issues/#findComment-487659 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.