Hello,

I have a php script. there is user and admin sections. The information is displayed in the user side (displaying adding new article) when added from admin side. But when I add a new article and refresh page. it does not come but after 2-3 refreshes It comes. same as the other pages I should refresh 2 times for articles to be displayed. What can cause this ???

While I am fetching data from database, I always open connection and close connection after fetching finishes and same as others. Can this be the reason of this ?

is the DB on local host or a remote machine?

is the DB on local host or a remote machine?

On localhost everything works fine. But now its in remote host and I got this problem

These could just be caching problems.

Meaning; your browser likely stores a copy of the page so when you re-enter it, rather than download the same page again, it shows the one it already downloaded.

Try hitting ctrl+f5 to refresh. That usually forces it to reload the page.

The page could also be cached by your ISP, and whatever Proxy you are behind (if any), and even your own router.

If you don't think this is the case, please show us the code you use to insert / fecth the data.

Does your code perhaps use transactions in a manner that might delay the commit?

Thank you for your reply. I am listing the criteries down here.

On localhost, everything works fine, newly added records are displayed in both admin and user pages.

On remote host, when I add a new record in the admin page, It is directly displayed in the admin page, no problem here.

When I go to user page and press refresh button on Firefox browser nothing changes then I press Ctr + F5, then I can now see the record, but When I go to an another page, I can not see the record there.
(Suppose that I am displating news on every page)

If this is becouse browser, It should cache localhost files too and I should not see the record change directly.

Before I had a blog script that I code, It had same annoying thing too and they are on the same host. Maybe I should test on another host ?

I dont think I had problem with my coding. Its simple.

This sure sounds like a caching problem.

The fact that CTRL+F5 brings up the data on one page, but navigating to another one does not, would support this.
It shows that the data is being sent by the server, but apparently not being shown by your browser.

You can try adding the following headers to your scripts.
They ask the browsers, and whatever proxies or routers they may pass through, to not cache the page, but to reload them every time:

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

Thank you very much Atli,
Yes It is a caching problem of my hosting. I uploaded my files to another host and test, now everthing is working fine. Why do they do this kind of thing ? for faster results. This is bad I think I should tell them to change this if possible or find another hosting.

Thank you very much for your help.

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.