Jump to content

Recommended Posts

Hello!

My server hosting company has updated PHP from 4 to 5 version, and now the header function doesn't work very well anymore.

It does load the new page everytime, like it should, but the data is not always refreshed. Not until I click "reload current page" from the browser. I'm using Firefox 3.6.3.

 

Here's the code which worked just fine few days ago:

$url="thepage.php";
header("Location: ".$url);
die();

 

I tried something like this, but that doesn't work either:

$url="thepage.php";
header("Refresh: 0; url=".$url);
die();

 

This is really nasty problem...

How can I fix it?

 

 

Link to comment
https://forums.phpfreaks.com/topic/235836-a-header-refreshing-problem/
Share on other sites

It does load the new page every time, like it should, but the data is not always refreshed.

 

Wouldn't that mean that the header() IS working, but that there is a problem with the code responsible for either setting or displaying the data?

 

How can I fix it?

 

You haven't posted any information telling us what IT is that didn't work (code and data.) For anyone one here to be able to help you with the problem, you would need to post enough of your code that demonstrates and reproduces the problem along with telling us exactly what data values are not always refreshed.

You're right, my explanation was a little vague, sorry.

 

This shows my problem. It should echo $num +1 every time the button is clicked, but it's not. $num will increase ONLY when "refresh page" from the browser is clicked.

 

<?
/*
CREATE TABLE `numbers` ( `num` TINYINT( 3 ) DEFAULT '0' );
INSERT INTO `numbers` ( `num` ) VALUES ( '1' );
*/

$db = mysql_connect("localhost", "username", "password"]) or die(mysql_error($db));
$sql_vars["db"] = $db;
mysql_select_db("dbname"], $db) or die(mysql_error($db));

switch($action) {
case "increase":
	mysql_query("update numbers set num=".(1+$_POST["newnum"]));
	$url="thispage.php";
	header("Location: ".$url);
	die();
break;
}

$num=mysql_result(mysql_query("select num from numbers"),0);

echo $num;

echo "<form action=\"thispage.php?action=increase\" method=\"POST\">";
echo "<input type=\"submit\" value=\"increase\">";
echo "<input name=\"newnum\" value=\"".$num."\" type=\"hidden\">";
echo "</form>";
?>

Actually, I have about the same question that phppaper's code would show. Is the header() redirect going to the thispage.php url (without the ?action=increase on the end of it)?

 

What exactly do you see in front of you after you submit the form, but before you refresh the page? Is is a blank page or is it the form/submit button?

Actually, I have about the same question that phppaper's code would show. Is the header() redirect going to the thispage.php url (without the ?action=increase on the end of it)?

 

What exactly do you see in front of you after you submit the form, but before you refresh the page? Is is a blank page or is it the form/submit button?

 

Sometimes nothing happens (button stays, number is the same) and sometimes the number is increased by one. But the mysql table is updated EVERY time.

If I click "refresh page" AFTER nothing was happened, the number is increased by one.

 

I've made more investigation and:

That example page is working on the Explorer! And with Chrome. But not with Firefox! (Firefox now updated to 4.01)

With Explorer and Chrome the number is increasing every time I click the button.

 

On my site, the problem is happening with every browser! Ok, that example code is not 100% equally constructed like a page on my site, but it should be close enough.

BUT it is strange thing also that my site's users haven't (yet..) reported any problems about this... so could this be happening in my end only?

I've tried with firefox, explorer, chorme, with three different computers (xp, vista). But the problem stays.

:wtf:

 

Ok, the problem is seen in this simple code:

<?
// thispage2.php
echo date('d.m.Y H:m:s');
echo "<br><a href=\"thispage2.php\">Reload</a>";
?>

 

I think the date should be updated every time the 'Reload' link is clicked?

Well, it's not..

If I keep clicking the link continuously, the date is updated in every 19 seconds sharp!

 

This has little to do with PHP anymore, but maybe someone could have an idea what causes this glich?

:shrug:

 

This is likely a caching problem, either on the web server or on a proxy located between where the web server is and where you are.

 

Problem solved. The server hosting company had implemented somekind of additional cache... Clearly wasn't working like it should  >:( so they removed it.

 

Thanks for the help.

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.