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.

Get Checked Unchecked Checkbox value in j-Query

<form id=”form1″ >
<div>
<div id=”testCheck”>
<input type=”checkbox” checked=”checked” value=”1″ />
<input type=”checkbox” checked=”checked” value=”2″ />
<input type=”checkbox” checked=”checked” value=”3″ />
<input type=”checkbox” checked=”checked” value=”4″ />
<input type=”checkbox” checked=”checked” value=”5″ />
<input type=”checkbox” checked=”checked” value=”6″ />
<input type=”checkbox” checked=”checked” value=”7″ />
<input type=”checkbox” checked=”checked” value=”8″ />
</div>
<input id=”testChk” type=”button” value=”Submit” />

<table id=”testTB”>
<thead>
<tr>
<th>test</th>
<th>chk boxes</th>
</tr>
</thead>
<tbody>
<tr><td>test</td><td><input type=”checkbox” checked=”checked” value=”1″ /></td></tr>
<tr><td>test</td><td><input type=”checkbox” checked=”checked” value=”2″ /></td></tr>
<tr><td>test</td><td><input type=”checkbox” checked=”checked” value=”3″ /></td></tr>
<tr><td>test</td><td><input type=”checkbox” checked=”checked” value=”4″ /></td></tr>
<tr><td>test</td><td><input type=”checkbox” checked=”checked” value=”5″ /></td></tr>
<tr><td>test</td><td><input type=”checkbox” checked=”checked” value=”6″ /></td></tr>
</tbody>
</table>
<input id=”tblSub” type=”button” value=”Submit” />
</div>
</form>

<script type=”text/javascript”>
//Write your code when Document is loaded
$(document).ready(function() {
$(“#testChk”).click(function() {
alert($(“#testCheck :checked”).size());
//function to print the value of each checked checkboxes
$(“#testCheck :checked”).each(function() {
alert(“value = ” + $(this).val());

});
});
$(“#tblSub”).click(function() {
//show count of all not checked checkboxes only
alert($(“#testTB :input:not(:checked)”).size());
//show count of all not checked elements
//alert($(“#testTB :not(:checked)”).size());

//function to print the value of each not checked checkboxes
$(“#testTB :input:not(:checked)”).each(function() {
alert(“value = ” + $(this).val());
});
});

});
</script>

Modify the URL without reloading the page

This new feature offers you a way to change the URL displayed in the browser* through javascript without reloading the page. It will also create a back-button event and you even have a state object you can interact with.

This means you won’t have to use the hash-hack anymore if you want add state to your AJAX-application, and search engines will be able to index your pages too.

So how does it work? Well, it’s fairly simple. In Chrome you write:

window.history.pushState(“object or string”, “Title”, “/new-url”);

Executing this line of code will change the URL to my-domain.com/new-url (3rd option). The “Title” string (2nd option) is intended to describe the new state, and will not change the title of the document as one might otherwise expect. The W3 documentation states:

“Titles associated with session history entries need not have any relation with the current title of the Document. The title of a session history entry is intended to explain the state of the document at that point, so that the user can navigate the document’s history.”

So if you want the document’s title to change to match the title of the history entry, you’ll need to write a hook for that (hint: just tie a function to the onpopstate event). Finally, “object or string” (1st option) is a way to pass an object to the state which you can then use to manipulate the page.

You can programmatically invoke the back-function by running:

window.history.back();
And you can of course go forward too:

window.history.forward();
Or even go to a specific history state:

window.history.go(2);
The object you pass as the first option to the pushState function will stay with each state, so if you go back in the history, you’ll get the object for that state. If you need to manipulate a state (instead of creating a new one) you can use:

window.history.replaceState(“object or string”, “Title”, “/another-new-url”);

Note that while this will change the URL of the page, it will not allow the user to click the back-button to go back to the previous state because you’re replacing the current state, not adding a new one. So, this is the correct behaviour.

Personally, I think the URL should be the first parameter and then the two other options should be optional. Regardless, this feature will certainly come in handy when working with AJAX- and Flash-applications that need state (read: bookmarkable pages and back-button support). Anyone looking to make their Flash- or AJAX-application indexable by search engines so they will get better raking in Google and the likes, should also have a look at this new feature.

The most prominent implementation of this HTML5-feature that I’ve seen is in the new Flickr layout. Here’s an example page (remember to enable the new layout if you haven’t already). Now, if you’re using the latest version of Chrome or Safari and click one of the sets, e.g. “Strobist”, it will slide open and the URL will change but you’ll notice that the page doesn’t reload.

It’s worth noting that Flickr uses replaceState instead of pushState – in other words, they don’t add a back-button event. I’m guessing they feel that switching back and forth between opened/closed sets is too small a change for a back-button event (I’d certainly agree with them on that decision), so instead they just replace the URL so if you copy/paste the link to a friend, they’ll see the exact same page that you did.

Another interesting thing is how Flickr still use the old hash-hack as a fallback if you’re running on browsers that don’t support this new HTML5-feature. I predict/hope that a lot of the plugins that help you easily implement the hash-hack will bake this into their core so people with new browsers can start reaping the benefits.

The latest versions of Chrome and Safari already have support for “onpopstate” and Firefox 4 will have support for it as well. Unfortunately, it seems like IE9 won’t be supporting this feature if we are to believe this Wikipedia article (“Trident” is IE’s layout engine).

Check out the W3 specification for more info.

* For security reasons, you can only change the path of the URL, not the domain itself. So you can change anything in the URL after my-domain.com/[change-the-stuff-here.html].