Hi,
I have one of those questions that can either be extremely complicated or extremely easy, depending on the approach. To start off, I am creating a feature on my website that requires the user to create an account and login to access it. Once the user is logged in, they stay logged in because a cookie is saved, which tells the site to display different things and give them access to their account based on the cookie's information. Like most websites that have you create an account, there are two main pages: the main log in and sign up page, and in this case the "song manager," which is the page that can only be accessed after the user logs in. Right now, the user is able to log in and log out perfectly fine by just creating a cookie and then deleting it, but the problem is that, after the user logs out, they are still able to access their account on the "song manager" page if they just go to the URL of that page, which is a BIG no no. But once I hit the refresh button, it correctly locks me out, so it is obviously a cache problem. In an attempt to fix it, I have already tried a couple of approaches.
First approach:
CODE
<?php
Header("Cache-control: private, no-cache");
Header("Expires: Mon, 26 Jun 1997 05:00:00 GMT");
Header("Pragma: no-cache");
header ("Last-Modified: " . gmdate ("D, d M Y H:i:s") . " GMT");
?>
This fixes the main problem, however, in the "song manager" I have buttons that process a form through another php page, which then includes the "song manager" page through a code like:
CODE
<?php
include "songmanager.php";
?>
The problem there is that, when I submit a form from the "song manager" page to the processing page, it submits successfully, but I also get errors that say:
Warning: Cannot add header information - headers already sent by (output started at /www/cgi/testchange.php:76) in /www/cgi/songmanager.php on line 6
I know this is because the "song manager" page is trying to add headers within testchange.php, but it can't, so I can't go with the "header(..."
Second approach:
Since the error was corrected when I hit the refresh button, I also tried making the page refresh once automatically when the page loaded. It's not exactly the smoothest way to handle it, but it was worth a try. My code looked something like this:
CODE
<?php
if (empty($_COOKIE['refreshed']))
{
setcookie('refreshed', 1);
header("Refresh: 0; url=testlogin.php");
}
else
{
setcookie('refreshed','',time()-3600);
}
?>
That was basically the method I used to refresh, but even with this method, it still came down to a cache problem.
So, to make a long story short, is there a way to clear the cache without using the php "header" in order to avoid the errors when the page is included in another page? If not, is there any way to fix this problem so that it actually keeps you out of the "song manager" when you log out?
Perhaps another method that I haven't tried is generating a random number and passing it through the URL every time the page is loaded to trick the computer into thinking it's a different page, but I'm afraid that people will be able to go back and load the page with a previous random number value, which will load the saved cache and mess it all up!
Thanks for any help.