how to header("Expires") in php
Results 1 to 5 of 5

Thread: how to header("Expires") in php

  1. #1
    Senior Member
    Join Date
    Oct 2011
    Posts
    243

    how to header("Expires") in php

    Hi,

    I want to ask how can I set the following in PHP with the current date to expire the page immediately?

    PHP Code:
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 

  2. #2
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    7,621
    Take a look at date(). You should be able to do that fairly easily, with a $date variable built with date() and then:

    PHP Code:
    header("Expires: $my_date_var"); 
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  3. #3
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,349
    Quote Originally Posted by jrahma View Post
    I want to ask how can I set the following in PHP with the current date to expire the page immediately?
    If for some reason your server's time isn't accurate, or the client's time isn't accurate, using the current time might not expire the page immediately. If that's your desire, it's recommended to use a date far in the past (such as what you're already doing).

  4. #4
    Senior Member
    Join Date
    Apr 2003
    Location
    Silver Lake
    Posts
    4,811
    Just wondering what you mean to accomplish by "expiring" the page. I've noticed that sending an expiration date may not be enough to prevent certain types of caching.
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

  5. #5
    Senior Member
    Join Date
    Jul 2007
    Posts
    3,619
    Searching for http cache headers should give a bunch of resources on the topic. But you should also add pragma no-cache, cache-control must revalidate and cache-lifetime 0.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •