Wednesday, August 25, 2010

Session time out in PHP

1.
session_start();
2.

3.
// set timeout period in seconds
4.
$inactive = 600;
5.

6.
// check to see if $_SESSION['timeout'] is set
7.
if(isset($_SESSION['timeout']) ) {
8.
$session_life = time() - $_SESSION['timeout'];
9.
if($session_life > $inactive)
10.
{ session_destroy(); header("Location: logoutpage.php"); }
11.
}
12.
$_SESSION['timeout'] = time();

Monday, August 23, 2010

Copy a file to the Control Panel


copy($_FILES['Image']['tmp_name'],"images/".$_FILES['Image']['name']);
?>

Database Connection in PHP

Connect the database

database name ="newdatabase" ;

mysql_select_db("$conn","databasename");
?>

Data Base Connection in PHP

Just Copy the following and paste in the file where ever you want

Conn.php

$conn=mysql_connect("hostname","username","password");
?>

For Localhost



$conn=mysql_connect("localhost","root","");
?>