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


MySQL  Time Duration
MySQL  Time Duration

You may want to check whether a particular date has passed using start date, time duration and current date  when the target date is not physically stored.

For clarity, consider a db table schema as follows.

+-----------+--------------------------+------------------+
| event_id | start_time               | duration_seconds |
+-----------+--------------------------+------------------+
| 005      |'2014-10-1 12:13:08'      | 86400            |
+-----------+--------------------------+------------------+

Here `duration_seconds` is stored using integers. If TIME is used, there 's a limit for 24 hrs.
If you want to get only adverts that have not expired, you will run a query like this.

SELECT * FROM  `events` WHERE TIME_TO_SEC(timediff(now(),start_time))<=`duration_seconds`;
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.
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;
    }

}


<?php
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', YOUR_.PEM_FILE);
stream_context_set_option($ctx, 'ssl', 'passphrase', YOUR_PASSPHRASE);
 
$fp = stream_socket_client(
        'ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
 
if (!$fp) {
    exit("Failed to connect: $err $errstr

");
}
 
echo 'Connected to APN
';
 
 
// Create the payload body
$body['aps'] = array(
    'badge' => +1,
    'alert' => 'Testing push notifications',
    'sound' => 'new_wall_paper.wav',
    'action-loc-key' => 'OK'
);
 
$payload = json_encode($body);
 
for ($i = 0; $i < count($tokens); $i++) {
    $msg = chr(0) . pack('n', 32) . pack('H*', $tokens [$i]) . pack('n', strlen($payload)) . $payload;
    fwrite($fp, $msg, strlen($msg));
}
 
echo "Completed sending messages";
fclose($fp);
?>




CI natively only allows for  single parameter in custom callbacks. For an instance see the following code.


$this->form_validation->set_rules
('hstate', 'State', 'required|callback_suburb_check[' . $suburb . ']');

If you need to pass multiple parameters, you have several options. Obviously you can change CI behaviour by subclassing the core library. But in this tutorial we follow the less pain approach. That 's to access required parameters via POST variables within your custom callback function. They are still available in this scope.

There is another way using your PHP string handling knowledge. Just formatting all the parameters as single string and passing to the callback function.


$parameters = 'first_arg' . '||' . 'second_arg' . '||' . 'third_arg';
$this->form_validation->set_rules
('some_field', 'Some Field Name', 'callback__my_callback_function['.$parameters.']');

Then in your callback,


function _my_callback_function($field_value, $second_parameter){
    list($first_param, $second_param, $third_param) = split('||', $second_parameter);
    ...
}
HTML5 Data Storage
HTML5 Data Storage



function supports_html5_storage() {
                try {
                    return 'sessionStorage' in window && window['sessionStorage'] !== null;
                } catch (e) {
                    return false;
                }
            }
            alert(supports_html5_storage());
Copyright © 2012 The Code Junction.