954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Page redirection not working in Firefox4

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['PHP_SELF'])" 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?..

an00p
Newbie Poster
12 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

Your code?

thejimgaudet
Newbie Poster
11 posts since Jun 2010
Reputation Points: 10
Solved Threads: 3
 

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>
an00p
Newbie Poster
12 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

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

tiggsy
Junior Poster
119 posts since Jul 2009
Reputation Points: 16
Solved Threads: 8
 

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['id_view'] and delete_confirm.php uses the value $_SESSION['user_id'].

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

an00p
Newbie Poster
12 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

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 "#"

tiggsy
Junior Poster
119 posts since Jul 2009
Reputation Points: 16
Solved Threads: 8
 

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

an00p
Newbie Poster
12 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

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

tiggsy
Junior Poster
119 posts since Jul 2009
Reputation Points: 16
Solved Threads: 8
 

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.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

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

an00p
Newbie Poster
12 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

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>
  }
}
tiggsy
Junior Poster
119 posts since Jul 2009
Reputation Points: 16
Solved Threads: 8
 

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

an00p
Newbie Poster
12 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: