coolabhijits Posted December 4, 2009 Share Posted December 4, 2009 <?php ob_start(); session_start(); function go() {$i=0; echo $i++ ; header("Location : http://127.0.0.1/login.php"); exit; } if(isset($_POST)) {//if started $name=$_POST["name"]; $password=$_POST["password"]; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("admin", $con); //echo "Connection established"; $result = mysql_query("SELECT password FROM log where name='".$name."'"); if(!$result)//checking for null { go(); } while($row = mysql_fetch_array($result)) { //echo "<br>inside fetching"; /* Checking for the correct password */ if($row['password']==$password) { $_SESSION['admin'] = $name;//setting session for admin // echo "\n 2error in header redirection in pass check"; go(); }//password comparision if ending }//row fetching while ending mysql_close($con); //echo "\n 3header redierection error"; go(); }//if check ending ?> Quote Link to comment https://forums.phpfreaks.com/topic/184003-help-plz-problem-with-header-redirection-urgent/ Share on other sites More sharing options...
mikesta707 Posted December 4, 2009 Share Posted December 4, 2009 First off, put your code in code tags please. Secondly, what exactly is the problem? Quote Link to comment https://forums.phpfreaks.com/topic/184003-help-plz-problem-with-header-redirection-urgent/#findComment-971390 Share on other sites More sharing options...
coolabhijits Posted December 4, 2009 Author Share Posted December 4, 2009 <?php ob_start(); session_start(); function go() {$i=0; echo $i++ ; header("Location : http://127.0.0.1/data_entry/"); exit; } if(isset($_POST)) {//if started $name=$_POST["name"]; $password=$_POST["password"]; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("admin", $con); //echo "Connection established"; $result = mysql_query("SELECT password FROM login where name='".$name."'"); if(!$result)//checking for null { go(); } while($row = mysql_fetch_array($result)) { //echo "<br>inside fetching"; /* Checking for the correct password */ if($row['password']==$password) { $_SESSION['admin'] = $name;//setting session for admin // echo "\n 2error in header redirection in pass check"; go(); }//password comparision if ending }//row fetching while ending mysql_close($con); //echo "\n 3header redierection error"; go(); }//if check ending ?> in this code i am unable to redirect using the go funtion .......i am basically checking if the user is logged in or not Quote Link to comment https://forums.phpfreaks.com/topic/184003-help-plz-problem-with-header-redirection-urgent/#findComment-971397 Share on other sites More sharing options...
mikesta707 Posted December 4, 2009 Share Posted December 4, 2009 this won't work $result = mysql_query("SELECT password FROM login where name='".$name."'"); if(!$result)//checking for null { go(); } at that query will return a result set since its a valid query (even if its an empty result set) you probably want to do something more like if (mysql_num_rows($result) < 1){//no rows returned go(); } Quote Link to comment https://forums.phpfreaks.com/topic/184003-help-plz-problem-with-header-redirection-urgent/#findComment-971401 Share on other sites More sharing options...
coolabhijits Posted December 4, 2009 Author Share Posted December 4, 2009 humm actually i m a newbee in php so i have done some harsh coding but my code is working with respect to authentication but it is not redirecting to my index page that is the main prob BRO!!!! Quote Link to comment https://forums.phpfreaks.com/topic/184003-help-plz-problem-with-header-redirection-urgent/#findComment-971405 Share on other sites More sharing options...
mikesta707 Posted December 4, 2009 Share Posted December 4, 2009 oh, didn't even see the other go() calls. Try turning error reporting on by adding the following to the top of your page error_reporting(E_ALL); ini_set("display_errors", 1); and post any errors you get Quote Link to comment https://forums.phpfreaks.com/topic/184003-help-plz-problem-with-header-redirection-urgent/#findComment-971408 Share on other sites More sharing options...
coolabhijits Posted December 4, 2009 Author Share Posted December 4, 2009 yup i done that but no error is displayed Quote Link to comment https://forums.phpfreaks.com/topic/184003-help-plz-problem-with-header-redirection-urgent/#findComment-971411 Share on other sites More sharing options...
Psycho Posted December 4, 2009 Share Posted December 4, 2009 The logic is messed up. For example if(!$result)//checking for null { go(); } 1. That does NOT check for null (i.e. empty results), that check to ensure there were no errors in the query. 2. You are not escaping the variables in your query and are leaving yourself open to SQL injection. 3. The go() function echo's text to the page before running the header() function. In which case you should have received an error stating that you cannot resend headers after content is sent. Wht is the purpose of the variable $i in that function? Makes no sense. <?php ob_start(); session_start(); function go() { header("Location : http://127.0.0.1/ajax/data_entry/"); exit; } if(isset($_POST)) { //if started if (!$con = mysql_connect("localhost","ultra","9968015024")) { die('Could not connect: ' . mysql_error()); } //echo "Connection established"; mysql_select_db("admin", $con); $name = mysql_real_escape_string($_POST["name"]); $password = mysql_real_escape_string($_POST["password"]); $query = "SELECT password FROM login where name='{$name}'"; $result = mysql_query($query); if(!$result) //Check for error { die("Error running query: $query<br>\n\n" . mysql_error()); } if(mysql_num_rows($result)===0)//checking for null { go(); } $row = mysql_fetch_assoc($result); if($row['password']==$password) //Checking the password { $_SESSION['admin'] = $name;//setting session for admin go(); }//password comparision if ending mysql_close($con); //echo "\n 3header redierection error"; go(); }//if check ending ?> Quote Link to comment https://forums.phpfreaks.com/topic/184003-help-plz-problem-with-header-redirection-urgent/#findComment-971431 Share on other sites More sharing options...
coolabhijits Posted December 4, 2009 Author Share Posted December 4, 2009 @MJDAMATO dude thanks for ur reply, it is really beneficial for me in future but the prob is still there i m not redirected to my index page ....... Quote Link to comment https://forums.phpfreaks.com/topic/184003-help-plz-problem-with-header-redirection-urgent/#findComment-971444 Share on other sites More sharing options...
premiso Posted December 4, 2009 Share Posted December 4, 2009 The issue is pretty simple: function go() { header("Location: http://127.0.0.1/ajax/data_entry/"); exit; } That will work, for headers doing Location : throws it off as it is not proper syntax. It should be Location: Try that and see if it works for Quote Link to comment https://forums.phpfreaks.com/topic/184003-help-plz-problem-with-header-redirection-urgent/#findComment-971450 Share on other sites More sharing options...
coolabhijits Posted December 4, 2009 Author Share Posted December 4, 2009 @above The issue is pretty simple: function go() { header("Location: http://127.0.0.1/ajax/data_entry/"); exit; } That will work, for headers doing Location : throws it off as it is not proper syntax. It should be Location: Try that and see if it works for thanks DUDE and mjdamato problem resolved........ Quote Link to comment https://forums.phpfreaks.com/topic/184003-help-plz-problem-with-header-redirection-urgent/#findComment-971465 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.