Ajax Counters (PHP)

Source: Internet
Author: User
Tags config functions get ip connect sql window
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 ();
?>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.