Get Remaining Time from given Expire future date

function ls_remaining_time( $expire_timestamp, $left_red = ‘right’ ){
if( !empty( $expire_timestamp ) && $expire_timestamp > -1 ){
$diff = $expire_timestamp – current_time( ‘timestamp’ );

if( $diff > 0 ){

$secondsInAMinute = 60;
$secondsInAnHour = 60 * $secondsInAMinute;
$secondsInADay = 24 * $secondsInAnHour;

/* extract days */
$days = floor( $diff / $secondsInADay );

/* extract hours */
$hourSeconds = $diff % $secondsInADay;
$hours = floor( $hourSeconds / $secondsInAnHour );

/* extract minutes */
$minuteSeconds = $hourSeconds % $secondsInAnHour;
$minutes = floor( $minuteSeconds / $secondsInAMinute );

/* extract the remaining seconds */
$remainingSeconds = $minuteSeconds % $secondsInAMinute;
$seconds = ceil( $remainingSeconds );

if( $days > 0 ){
if( $days == 1 ){
$remaining = ‘1 ‘.__( ‘day’, ‘couponxl’ );
}
else{
$remaining = $days.’ ‘.__( ‘days’, ‘couponxl’ );
}
}
else if( $hours > 0 ){
if( $hours == 1 ){
$remaining = ‘1 ‘.__( ‘hour’, ‘couponxl’ );
}
else{
$remaining = $hours.’ ‘.__( ‘hours’, ‘couponxl’ );
}
}
else if( $minutes > 0 ){
if( $minutes == 1 ){
$remaining = ‘1 ‘.__( ‘minute’, ‘couponxl’ );
}
else{
$remaining = $minutes.’ ‘.__( ‘minutes’, ‘couponxl’ );
}
}
else if( $seconds > 0 ){
if( $seconds == 1 ){
$remaining = ‘1 ‘.__( ‘second’, ‘couponxl’ );
}
else{
$remaining = $seconds.’ ‘.__( ‘seconds’, ‘couponxl’ );
}
}
}
else{
$remaining = __( ‘Expired’, ‘couponxl’ );
}
}
else{
$remaining = __( ‘Unlimited Time’, ‘couponxl’ );
}

if( $left_red == ‘right’ ){
return __( ‘Expires in: ‘, ‘couponxl’ ).'<span class=”red-meta”>’.$remaining.'</span>';
}
else{
return ‘<span class=”red-meta”>’.__( ‘Expires in: ‘, ‘couponxl’ ).'</span>’.$remaining;
}
}

Get url by page template name in WordPress

/* get url by page template */
function ls_get_permalink_by_tpl( $template_name ){
$page = get_pages(array(
‘meta_key’ => ‘_wp_page_template’,
‘meta_value’ => $template_name . ‘.php’
));
if(!empty($page)){
return get_permalink( $page[0]->ID );
}
else{
return “javascript:;”;
}
}

 

Now call

<form method=”post” action=”<?php echo ls_get_permalink_by_tpl( ‘page-tpl_register’ ) ?>”>

</form>

//page-tpl_register is a file name without .php extension

 

Destroy idle User Session in Php

in User Login page set session after user successfully login.

<?php
$_SESSION[‘last_active_time’]=time();
?>

In Common Page which are every time load.

<?php
session_start();
$idletime=60;//after 60 seconds idle time the user gets logged out.
if (time()-$_SESSION[‘last_active_time’]>$idletime){
session_destroy();
session_unset();
}
else
{
$_SESSION[‘last_active_time’]=time();
}
?>

User Gravatar from an Email Address in Php

function get_gravatar( $email, $s = 80, $d = ‘404’, $r = ‘x’, $img = false, $atts = array() ){

$url = ‘http://www.gravatar.com/avatar/';
$url .= md5(strtolower(trim($email)));
$url .= “?s=$s&d=$d&r=$r”;
if ( $img ){

$url = ‘<img src=”‘ . $url . ‘”‘;

foreach ( $atts as $key => $val )
$url .= ‘ ‘ . $key . ‘=”‘ . $val . ‘”‘;
$url .= ‘ />';
return $url;
}
$headers = @get_headers($url);
if (!preg_match(“|200|”, $headers[0])) {
$has_valid_avatar = ‘no';
} else {
$has_valid_avatar = ‘yes';
}
return $has_valid_avatar;
}

change crawl rate for Google Search Engine spider

If you want Google Search Engine spiders to crawl your web pages faster than normal, you could request it through Google webmaster tools.

Login to Google Webmaster Tools, select the site for which you want to make the changes and follow the steps below:

1. Click on “Site Configuration” on the navigation on the left.

2. Click on “Settings”

3. Check the option “Set custom crawl rate” near the crawl rate heading.

4. Move the slider to the right to increase the crawl rate. You may increase it to the highest possible value, but remember this could cause an overhead to your server.