The first method: using the AltaVista search engine to implement
This method is to check the number of links with your site. This is accomplished with AltaVista search engines. Here, we use the following search engine:
http://www.altavista.com/cgi-bin/query?kl=XX&pg=q&text=yes&q=link:&search= Search.
This is a text version of AltaVista. This saves us a lot of code that needs parsing HTML. Next, we use Rawurlencode () to process our exact URL to ensure that AltaVista can handle it correctly. Processed as follows:
$url = "http://www.oso.com.cn";
$url _encoded = Rawurlencode ($url);
$url _to_check = "Http://www.altavista.com/cgi-bin/query?"
Kl=xx&pg=q&text=yes&q=link: $url _encoded&search=search ";
This allows us to fetch the URL back through the file () function.
$num _searched = file ($url _to_check);
The file we are retrieving is now stored in the array $num_searched. Now to find the text we want in the array "about (. *)
pages found. "。 (. *) expressed in any thing. Also, if no one links our url,altavista will show "AltaVista found
no document matching your query." Because we want to know how many people are linking to our URL, that text will be looked at
for 0 people link.
$url = "http://www.oso.com.cn";
$url _encoded = Rawurlencode ($url);
$url _to_check =
"Http://www.altavista.com/cgi-bin/query?kl=XX&pg=q&text=yes&q=link: $urL_encoded&search=search ";
$num _searched = file ($url _to_check);
for ($i = 0; $i < count ($num _searched); $i) {
if (eregi (. *) pages found., $num _searched[$i)) {
$total _links = eregi_replace ("
About (. *) pages found.", "1", $num _searched[$i]);
}
ElseIf (eregi ("AltaVista found no document matching your query.", $num _searched[$i])) {
$total _links = "0";
}
so that we can get our search results by printing statements:
Print ("$total _links people are linking to $url");
The second method: using the MySQL database The following is an article I posted, from the PHP Chinese users, the way is to use the temporary data table processing the current connection, the details are as follows:
***************************************
First, build a table with the MySQL tool:
CREATE table ccol (
ID integer NOT NULL auto_increment, #记录的ID IP char not NULL, #访问者的IP地址
Dtstamp datetime NOT NULL, #最后访问时间
URI char (255), #访问者请求的URI
Primary key (ID)
);
Then, write a section of PHP code:
/*
File: Ccol.php-concurrent Online statistics
Objective: To count the number of people browsing at the same time
Author: Hunte, hunte@phpuser.c Om
Modify: 2000-4-25
*/
$duration = 1800;
require "db.php";
//contains Dbsql, details can refer to my another article
$ccol =new dbsql;
$ccol->connect ();
$ccol->query ("DELETE from Ccol WHERE
(Unix_timestamp (now))-unix_timestamp (Dtstamp)) > $duration");
//Delete records for more than half an hour
$ccol->query ("select * from Ccol WHERE ip=" $REMOTE _addr ");
//To determine if the current IP exists in this table
if ($ccol->nf ()) {
$ccol->next_record ()//Move down pointer to the array of records found
$id = $ccol->f ("id" );
$ccol->query ("UPDATE ccol SET Dtstamp=now (), uri=" $REQUEST _uri "WHERE id= $id");
//Set last access time and access page
else{
$ccol->query (INSERT into Ccol VALUES (0, "$REMOTE _addr", Now (), "$REQUEST _uri") ");
}
$ccol->query ("Select COUNT (*) as Ccol from Ccol WHERE
(Unix_timestamp (now ())-unix_timestamp (Dtstamp)) <= $duration ");
Find the record in half an hour, and the WHERE clause that follows is optional--the excess time has been removed
$ccol->next_record ()
echo "Online number:", $ccol->f ("Ccol");
$ccol->free_result ();
How to use it? Call this program on top of each page of the site.
Of course, there is room for improvement in this piece of code. For example, it is unnecessary and inefficient to delete a half hour record before each call.
What can be done for a longer period of time, such as 6 hours. Let's think about it, I won't say it.
This method as long as a little modification, you can send other uses, such as session management, Web site access statistics analysis.