I run a site and once in a while users contact me because they either can't log in, or can log in but have problems submitting forms (the forms are on protected pages, using PHP sessions). Until now, I've been able to tell users to just switch browsers, and the problem cleared up: I figured that it was some sort of browser issue since it wasn't every user who was having this issue. Further, all problem users were using IE. I then thought that perhaps it was an IE specific problem until a new user had the same issue on Chrome/Firefox (I logged into the users account on 2 different machines and was not able to replicate the Chrome/Firefox issue).
After doing some digging, I now think the problem might be session related. This site says that:
Older cache files and cookies also need to be cleared before you visit secure areas like a payment portal or a shopping cart. “Session expired” is a common notification if old browser cache and cookies haven’t been junked.
After doing some further digging on Stackoverflow, I found a community wiki started by @BalusC saying that the proper way to avoid caching a page via php would be to use:
header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Pragma: no-cache'); // HTTP 1.0.
header('Expires: 0'); // Proxies.
With the above in mind, I have a couple of questions:
- Would I just put the above code on my login screen? It would seem to me that if I put it on any page where the user were logged in, then they would be logged out since the session won't be cached.
- If I use a CDN (CLoudflare), would their caching process override what I write on the specific page?
Thanks!
EDIT:
My login page is as follows:
<div id="login_form">
<form id="login" method="post">
<?php $login_problem = FALSE;
if (isset($_POST['signin']) && $failed) {
$login_problem = TRUE;
$login_error_result ='<a href="/admin/forgotten.php">Forget something?</a>';
}
?>
<table>
<tr>
<td>
<label for="username">Username:</label>
<input name="username" id="username" type="text" maxlength="15" />
</td>
<td colspan="2"><label for="password">Password: <?php if ($login_problem) {
echo $login_error_result;}?></label>
<input type="password" id="password" name="password" maxlength="15"/>
</td>
<td id="login_submit" >
<input type="submit" name="signin" class="submit" value="Sign in!" />
</td>
</tr>
</table>
</form>
</div>