iamdash
iamdash

Reputation: 449

Page expiry - PHP/CakePHP and Internet Explorer

I have a search box on my site, whereby the user enters a term and results are displayed. When they click one of the results (a product) they get taken to the product page. When they then hit the back button, they get shown a "Warning: this page has expired" message.

I am using CakePHP on Apache, and have been advised that I need to change session.cache_control? I have tried chaning it to private in htaccess, but it does not seem to have helped.

Any help much appreciated.

Cheers, D

Upvotes: 3

Views: 264

Answers (2)

deizel.
deizel.

Reputation: 11232

You can also use the Post/Redirect/Get design pattern pattern to avoid this. For example:

function index($searchTerms = null) {
    if (isset($this->data['Model']['search_terms'])) {
        $this->redirect(array($this->data['Model']['search_terms']));
    }
    // your normal code here.
}

This will result in URLs like /controller/action/search+terms instead of /controller/action?search_terms=search+terms, and search terms will be passed to the action as a parameter (ie. $searchTerms in this case).

Upvotes: 0

symcbean
symcbean

Reputation: 48367

This is nothing to do with CakePHP nor sessions. Indeed, the issue arises in all web programming languages.

The solution is to make the search results page cacheable - I would imagine that you're not updating your catalog every 5 minutes?

To make it cacheable you need to ensure that the search terms are sent using a GET rather than a POST, then set the right headers to enable the browser to cache the page, e.g.

 header('Cache-Control: max-age=360'); // allows browser to keep for 1 hour

....and if you're using sessions which may constrict the visiblity of certain products in the search:

 header('Varies: Cookie');

C.

Upvotes: 2

Related Questions