Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
PHP Page appears to be caching for some users but not for others?

I have a strange situation and I'm hoping someone might have experienced this before and know what possible scenarios might cause this to occur.

I have a PHP website which accesses data from an SQL database. Users fill out a form to add or edit data which is POSTED and the data is written to the database. If the user is editing existing data, the php loads the data needed for the form, and I use JavaScript to fill the data into the appropriate fields once the page has loaded.

All of this works correctly for me on all the machines I've tested, and most users.

HOWEVER... SOME users are reporting that they are not seeing the correct data in their forms, but rather outdated information. Thus, when these users "edit" a form, rather than seeing the information that is currently contained within the database, they see old information.

My understanding is that (normally) php files aren't cached since they are executed on the server and then the final product is being handed to the user. Is there any situations which might cause a certain user to somehow cache these "assembled" files once they are received from the server and then reloaded the next time the page loads?

Example:

Today a client was trying to edit the information using the form. They called me because a field was showing something incorrect.

I logged into my site and loaded the same form. My form was showing the correct data (as contained within the SQL database), while theirs was showing different data.

Two different users looking at the same php webpage, and same form, using the same browser (chrome), which should be displaying the same data, but is not.

I'm baffled as to how to trace this issue and fix it.

UPDATE:

After playing around a bit, I suspect that it may be an issue of the client's browser or internet being a bit slower than most, which might be causing the Javascript to execute before the page is fully loaded.

I changed it to execute the javascript onload using jQuery which might fix the issue until I can recode a more elegant solution, but have not yet heard back from this particular client so don't know if that fixed the issue for them quite yet...but it certainly won't hurt.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Perhaps the browser is caching the page?
To ensure no cache for the browser, please try it in PHP

<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
about 4 years ago · Juan Pablo Isaza Report

0

Just like you mentioned that PHP executed on the server so they will not be cached. However, browsers basically cache the frequent or recent form data for later use. Lets discuss this in details.

By default, browser watch and remember all the information filled through <input> fields on websites. This enables the browser to offer autocompletion (that is, suggest possible completions for fields that the user has started typing in) or autofill.

These features are enabled by default but user can disable this feature on demand. However, browser doesn't cache some sensitive information like pin code etc. To disable this browser default cache behavior you can set the autocomplete attribute to "off":

autocomplete="off"

You can do this either for an entire form, or for specific input elements in a form:

<form method="post" action="/form" autocomplete="off">
 […]
</form>

Setting autocomplete on form has two effects.

  1. It notify the browser not to save data entered by user in form fields for later auto-completion
  2. it prevents the browser from caching form data in the session history. When data is cached one time, it is used later on when user uses the same form and relevant input fields. In short, the cached data is mapped to the related input fields.

However, a important point to note that the autocomplete behavior doesn't work for the login forms. i.e the forms includes the username and password fields. Additionally, the browser enables the user to choose a master password that the browser will use to encrypt stored login details. For this reason, many modern browsers do not support autocomplete="off" for login fields:

  1. If a site sets autocomplete="off" for a , and the form includes username and password input fields, then the browser still offers to remember this login, and if the user agrees, the browser will autofill those fields the next time the user visits the page.
  2. If a site sets autocomplete="off" for username and password fields, then the browser still offers to remember this login, and if the user agrees, the browser will autofill those fields the next time the user visits the page.

However, last but not least, there is genuine solution to eliminate this issue and this is filling the user edit form server side. i.e through PHP. In this case there will be no concern of Caching problem and everything will work smoothly. i.e

<input type="text" value="<?php echo $username; ?>" name="firstname"/>

I hope this discussion will help you!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!