Jump to content

help plz -----problem with header redirection --------urgent


coolabhijits

Recommended Posts

<?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

?>

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

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();
}

Link to comment
Share on other sites

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
?>

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

@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........

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.