Home >Backend Development >PHP Tutorial >Implementation of the current number of people online on the website_PHP tutorial
Probably the most important component of a website is the number of sites that link to you. This tutorial will show you a simple way to do it using the AltaVista
search engine.
First, we need to prepare the URL to be used in the script. This can be used:
http://www.altavista.com/cgi-bin/query?kl=XX&pg=q&text=yes&q=link%3A&search=Search.
You should know that this is a text version of AltaVista. This saves us a lot of code that needs to parse HTML. Next, we
need the exact URL. We should use rawurlencode() to process the URL to ensure Altavista can handle it correctly.
$url = http://www.php.net;
$url_encoded = rawurlencode($url);
$url_to_check = "http://www.altavista .com/cgi-bin/query?
kl=XX&pg=q&text=yes&q=link%3A$url_encoded&search=Search";
?>
Now we have all the URLs we need. It's time for us to retrieve the URL. This step is done by using the file() function.
$url = http://www.php.net;
$url_encoded = rawurlencode($url);
$url_to_check = "http://www.altavista.com/ cgi-bin/query?
kl=XX&pg=q&text=yes&q=link%3A$url_encoded&search=Search";
$alta_search = file($url_to_check);
?>
Now what we have captured The returned file has been stored in the array $alta_search. We now want to find the text we want in the array. The text we want is "About (.*) pages found. ". (.*) means anything between two words. Moreover, if no one links to our URL, AltaVista will display "AltaVista found no document matching your query.". Since we want to know how many people are linking to our URL, that text will be treated as 0 people linking.