Like us on Facebook and stand a chance to win pen drives!

Prevent HTTP Cache with PHP

HTTP Cache
HTTP Cache
HTTP Cache can be troublesome during development in some occasions specially in developing and testing web services, testing endpoints. We can use PHP headers to prevent and disable HTTP cache. 

header("Content-Type: application/json");
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

 Other than the above, there are other techniques of prevent  browser caching.

0 comments:

CodeIgniter Like Flash Data in PHP

CodeIgniter
CodeIgniter



class FlashMessage {

    public static function render() {
        if (!isset($_SESSION['my_my_messages'])) {
            return null;
        }
        $my_messages = $_SESSION['my_messages'];
        unset($_SESSION['my_messages']);
        return implode('<br/>', $my_messages);
    }

    public static function add($message) {
        if (!isset($_SESSION['my_messages'])) {
            $_SESSION['my_messages'] = array();
        }
        $_SESSION['my_messages'][] = $message;
    }

}

0 comments:

Copyright © 2012 The Code Junction.