Saturday, October 9, 2010
Saturday, September 18, 2010
MYSQL Connection In PHP
$connect = mysql_connect("localhost","username","passowrd");
if (!$connect)
{
die('not conneced: ' . mysql_error());
}
?>
if (!$connect)
{
die('not conneced: ' . mysql_error());
}
?>
Arrays In PHP
$fruits[0]="mango";
$fruits[1]="orange";
$fruits[2]="banana";
$fruits[3]="pineapple";
echo $fruits[0] . " and " . $fruits[1] . " are fruits.";
?>
$fruits[1]="orange";
$fruits[2]="banana";
$fruits[3]="pineapple";
echo $fruits[0] . " and " . $fruits[1] . " are fruits.";
?>
Functions In PHP
function writeName()
{
echo "Kai Jim Refsnes";
}
echo "My name is ";
writeName();
?>
{
echo "Kai Jim Refsnes";
}
echo "My name is ";
writeName();
?>
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();
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");
?>
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","");
?>
Conn.php
$conn=mysql_connect("hostname","username","password");
?>
For Localhost
$conn=mysql_connect("localhost","root","");
?>
Subscribe to:
Posts (Atom)