Ajax| counter
These days just touch Ajax, write a very simple counter.
The client file counter.htm is used as a template, counter.php calls the counter.htm template.
When accessing counter.php, the database records IP, time, counter plus one.
XMLHttpRequest sends a request to counter_action.php, counter_action.php returns a number.
function settimeout () sets the automatic update time.
Counter.htm List
"Http://www.w3.org/TR/html4/loose.dtd"
< Html>
< Title>ajax counter
ajax counter
counter.php List
Include_once ("./config/connect.php");
Include_once ("./private/functions.php");
$ip = GetIP (); Get IP, function defined in functions.php
$time = time ();
Accessing the database
$sql = "INSERT into ' counter ' VALUES (NULL, ' $ip ', ' $time ')";
$rs = $conn->execute ($sql);
Parsing templates
$tpl->set_file ("File", "templates/counter.htm");
$TPL->parse ("main", "file");
$TPL->p ("main");
@ $rs->close ();
@ $conn->close ();
?>
counter_action.php List
Include_once ("./config/connect.php");
Include_once ("./private/functions.php");
Accessing the database
$sql = "SELECT * from ' counter '";
$rs = $conn->execute ($sql);
$counter = $rs->rowcount ();
$counter + +;
Echo $counter;
Releasing a database handle
@ $rs->close ();
@ $conn->close ();
?>