Hello Friends,

I have an issue after upgrading my firefox to version 4. This issue was there in IE8 but worked nicely in firefox3

Here is my issue:

I have a page with three forms and each form posts using "htmlentities($_SERVER)" action that is to the same page. Based on the posted value This page redirects to different pages.

This is not working any more and the same page is displayed.

What could be the reason?..

Here is my code:

<?
session_start();
include 'includes/auth.php';
include 'includes/config.php';
$_SESSION['page']="users_list";
if ($_POST)
{
	if (isset($_POST['users_view']))
	{
		$_SESSION['id_view'] = $_POST['user_view'];
		header( 'Location: users_view.php' );
		exit;
	}
	elseif (isset($_POST['users_delete']))
	{
		$_SESSION['user_id'] = $_POST['user_delete'];
		header( 'Location: delete_confirm.php' );
		exit;
	}
}

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
........
........
</body>
</html>

$_SERVER will surely just end up on the current page, so why not just use # and use hidden fields to transfer any data you need?

I need to POST data to the same page as the code below will redirect to different pages based on the POST values.

if ($_POST)
{
if (isset($_POST['users_view']))
{
$_SESSION['id_view'] = $_POST['user_view'];
header( 'Location: users_view.php' );
exit;
}
elseif (isset($_POST['users_delete']))
{
$_SESSION['user_id'] = $_POST['user_delete'];
header( 'Location: delete_confirm.php' );
exit;
}
}

The page "users_view.php" works on the value $_SESSION and delete_confirm.php uses the value $_SESSION.

It was working perfect until I upgrade firefox from version 3 to 4.

Yes, I understand you're going to the current page. My question was why you're choosing to use a global php variable to do so when you can just use "#"

I wasn't aware of it. Thank you for letting me know the use of "#"

But here the issue is not with posting to the same page. The issue is it doesn't redirect to other pages.

The POST check including page redirection is done before generating html codes. That is before <html></html>.

Update: Its working fine in "Google Chrome".

I may be wrong, but I think you have to set the session up after the header commands if they are to work.

Member Avatar for diafol

IMO: sending a form to its own page is not a good idea. You should send it to a form handler, otherwise, reload/refresh causes problems.

That's correct. But in my case the page redirects to another one(eg: user_view.php) with the form data after the form is submitted to it. The page checks for the form data ("if ($_POST)")before the html is generated (ie. before <html></html>).
If the form is not submitted, the page acts just like a normal page and reload/refresh won't have any effect on the page.

If this method no longer works, or only in certain browsers, then instead of redirecting, you could use code like this:

<?
session_start();
include 'includes/auth.php';
include 'includes/config.php';
$_SESSION['page']="users_list";
if ($_POST)
{
	if (isset($_POST['users_view']))
	{
		$_SESSION['id_view'] = $_POST['user_view'];
		include "./users_view.php";
	}
	elseif (isset($_POST['users_delete']))
	{
		$_SESSION['user_id'] = $_POST['user_delete'];
		include "./delete_confirm.php";
	}
	else 
	{
    $sql="SELECT * FROM $tbl_name";
    $result=mysql_query($sql);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test</title>
    </head>
    <body>
    ........
    ........
    </body>
    </html>
  }
}

I have fixed this issue..

In my form, I am using image instead of button to submit the form:

echo "<form name=formuser action=# method=post>"
echo "<input type=hidden value=".$rows['user_id']." name=user_id />";
echo "<input type=image src=images/more.png value=users_view name=users_view title=View />";
echo "</form>";

and the PHP code at the beginning checks if "users_view" is set (i.e. the image )

if (isset($_POST['users_view']))

I changed this if condition to check if "user_id" is set (i.e. hidden field)

if (isset($_POST['users_id']))

After that everything is working fine as before.

Thank you all for the support :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.