Saturday, July 6, 2013

how to keep a session alive for 30 minutes and then destroy it in php

session.gc_maxlifetime
session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and cleaned up. Garbage collection occurs during session start.
But the garbage collector is only started with a probability of session.gc_probability divided by session.gc_divisor. And using the default values for that options (1 and 100 respectively), the chance is only at 1%.
Well, you could argue to simply adjust these values so that the garbage collector is started more often. But when the garbage collector is started, it will check the validity for every registered session. And that is cost-intensive.
Furthermore, when using PHP’s default session save handler files, the session data is stored in files in a path specified in session.save_path. With that session handler the age of the session data is calculated on the file’s last modification date and not the last access date:
Note: If you are using the default file-based session handler, your filesystem must keep track of access times (atime). Windows FAT does not so you will have to come up with another way to handle garbage collecting your session if you are stuck with a FAT filesystem or any other filesystem where atime tracking is not available. Since PHP 4.2.3 it has used mtime (modified date) instead of atime. So, you won't have problems with filesystems where atime tracking is not available.
So it additionally might occur that a session data file is deleted while the session itself is still considered as valid because the session data was not updated recently.
And second:
session.cookie_lifetime
session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. […]

Wordpress custom search post and contents and by author name from wp_posts, wp_postmeta,wp_term_relationships tables

my custom wordpress search functinality you can help by my code please follow my code

-----------------------------------------------------------------------------------------------------------
 <form action="?page_id=155" method="POST" name="myForm" onSubmit="return validateForm()">
 
 
   <div class="search">

   <input type="submit" class="src-img" value="" name="sub">
        <input  value="Search Title And Author" onFocus="if(this.value=='Search Title And Author') this.value='';" onBlur="if(this.value=='') this.value='Search Title And Author';" name="search" id="search" type="text" class="src" />
<select name="authornamesearch"  class="select-src">
<option value="0">Select Author</option>
<option value="Bikash ranjan">Bikash ranjan</option>
<option value="Snatosh nayak">Snatosh nayak</option>
<option value="Himansu swain">Himansu swain</option>
<option value="Amara behera">Amara behera</option>

</select>
<input type="submit" class="src-btn" value="Search" name="subsearch">
   
      </div>
</form>
------------------------------------------Search Request handler page-------------------------------------------
  <?php
$search =trim($_REQUEST['search']);
$getAuthor=trim($_REQUEST['authornamesearch']);
$searchcln=trim(mysql_real_escape_string($search));
$getAuthorln=trim(mysql_real_escape_string($getAuthor));
$uarr = array();

if(($search!='Search Title And Author')or($getAuthor!=''))
{

if(($search!='Search Title And Author')&&($getAuthor!="0"))
{
$where ="wpmt.meta_key = 'author_name' AND wpmt.meta_value ='$getAuthorln' and (wp.post_title LIKE '%$searchcln%' or wp.post_content like '%$searchcln%')
AND wp.post_type = 'post' AND wtr.term_taxonomy_id != '1' AND wp.post_status <> 'trash'";

}
else if(($search=='Search Title And Author')&&($getAuthor!="0"))
{

$where ="wpmt.meta_key = 'author_name' AND wpmt.meta_value LIKE '%$getAuthorln%' AND wp.post_type = 'post' AND wtr.term_taxonomy_id != '1' AND wp.post_status <> 'trash'";
}
else{
  $where ="(wp.post_content like '%$searchcln%' AND wp.post_status ='publish' AND wp.post_type='post' and wtr.term_taxonomy_id != '1' AND wp.post_status <> 'trash')
            or (wp.post_title LIKE '%$searchcln%' AND wp.post_status ='publish' AND wp.post_type='post' and wtr.term_taxonomy_id != '1' AND wp.post_status <> 'trash')
or(wpmt.meta_key='author_name' AND wpmt.meta_value like '%$searchcln%' AND wp.post_type='post' and wtr.term_taxonomy_id != '1' AND wp.post_status <> 'trash')";
    }

$sql_query="SELECT distinct wp.* FROM
                           wp_posts wp
    INNER JOIN                 wp_term_relationships wtr
ON                         wtr.object_id = wp.ID
INNER JOIN                 wp_postmeta wpmt
ON                         wpmt.post_id = wp.ID
WHERE $where";
//echo $sql_query;
$rs = @mysql_query($sql_query);
$numberOfRows = @mysql_num_rows($rs);
if($numberOfRows>=1)
{
$p=0;
while($row = @mysql_fetch_array($rs))
{
$uarr[$p]['ID'] = $row['ID'];
//$uarr[$p]['post_content'] = $row['post_content'];
$uarr[$p]['post_title'] = $row['post_title'];
//$uarr[$p]['post_name'] = $row['post_name'];
//$uarr[$p]['guid'] = $row['guid'];
$p++;
}
}else
{
$message= "<h2 style='color:red;'>Not found&nbsp;".$search."&nbsp; in our book`s categories</h2>";
}


}


?>