KidsLovePC Contact Us
  Home   PHP  Graphics ASP  JavaScript   J2EE  HTML  JAVA   Swing   Webtip  Forums  Lyric  Free sheet music  Ringtones

Reciprocal link check by PHP

Getting reciprocal links is an important approach for search engine optimization. In order to rank higher in search engine search results, a web site usually maintains a huge amount of reciprocal links in its database.

To make reciprocal links update, web masters usually check these reciprocal links to see if they still have their own web URL or not. If not they will delete the corresponding reciprocal links from their database.

Reciprocal link MySQL database

Assume a web master put all his reciprocal links in a table named RLINKS in MySQL database, which has column,named backlink,storing reciprocal links.

The job for PHP reciprocal link checking is to pull out those reciprocal links from database and check them one by one to see if they still keep your web URL. If the reciprocal links lost your URL, you delete them from your database.

if you have read the lesson Send bulk emails in PHP, you will feel familiar with the following code.

Pull out reciprocal links from database

First, you need pull out reciprocal links from MySQL database using the following code:

//open database connection
$username = "yourname";
$password = "yourpassword"; //input your password here.
$database = "yourdb";
//connect to database
$link=mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("<b>Unable to specified database</b>");

//retrieve reciprocal links
$query="select backlink from RLINKS";
$result=mysql_query($query) or die('Error, query failed');

Check reciprocal link

Now, we need loop through the result set to check existence of your web URL in those reciprocal links.

$row=0;
$numrows=mysql_num_rows($result);

$myURL="http://wwww.yoursite.com";

//loop through reciprocal links
while($row<$numrows)
{
$backlink=mysql_result($result,$row,"backlink");
$check=linkcheck($myURL,$backlink);

//if reciprocal link doesn't have your url, delete from your database
if($check==null)
{
  mysql_query("delete from RLINKS where backlink='$backlink'") or die('Error, query failed');
}
$row++;
}

//check reciprocal link function
function linkcheck($mylink,$link)
{
$html = implode('', file($link));
$pos = strpos($html,$mylink);
return $pos;
}
mysql_close($link);

The above code use while() loop through the result set. $backlink get the reciprocal link from result set. function linkcheck is to check your URL existence in reciprocal link. It converts the reciprocal link to a string and try to find your URL (another string) in it by using strpos($html,$mylink);.

If $check is null, it means there is no your URL in reciprocal link. Then, you delete this reciprocal link from your database by calling  mysql_query("delete from RLINKS where backlink='$backlink'").

Put together

Put the above code together as following and save it as checklink.php(or whatever name ).

Just remember to change the $myURL to your web site URL. Launch it in your browser like : http://www.yoursite.com/checklink.php or you ran it locally: http://localhost/checklink.php. It should do the trick.

 

//open database connection
$username = "yourname";
$password = "yourpassword"; //input your password here.
$database = "yourdb";
//connect to database
$link=mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("<b>Unable to specified database</b>");

//retrieve reciprocal links
$query="select backlink from RLINKS";
$result=mysql_query($query) or die('Error, query failed');

$row=0;
$numrows=mysql_num_rows($result);

//change to your URL
$myURL="http://wwww.yoursite.com";

//loop through reciprocal links
while($row<$numrows)
{
$backlink=mysql_result($result,$row,"backlink");
$check=linkcheck($myURL,$backlink);

//if reciprocal link doesn't have your url, delete from your database
if($check==null)
{
  mysql_query("delete from RLINKS where backlink='$backlink'") or die('Error, query failed');
}
$row++;
}

//check reciprocal link function
function linkcheck($mylink,$link)
{
$html = implode('', file($link));
$pos = strpos($html,$mylink);
return $pos;
}
mysql_close($link);

 

PHP Calendar
Comprehensive PHP Web Calendar
Configurable PHP Calendar
PHP Calendar
PHP Image Processing
PHP grahic softwares
PHP create real-time dynamic chart
create antispam image(image verification)
Add water mark to image
PHP Image processing introduction
Add text on Image
Create thumbnail for image
Create image from text on fly
PHP code sample
PHP create dynamic PDF with FPDF
PHP create dynamic PDF with PDFLib
PHP create dynamic PDF with ClibPDF
Improved PHP configurable hit counter
Install phpMyAdmin,MySql, PHP
PhpMyAdmin export/import data
A simple PHP RSS feed reader
PHP include (SSI)
Working with Forms
PHP formmail Generator
Using phpMyAdmin Create Database
Insert Form Data into Database
Retrieve data from Database
Retrieve multiple records
Batch insert text using phpMyAdmin
Using phpMyAdmin insert binary file
Insert binary file using PHP code
Using form insert binary file into MySQL
Retrieve binary file from MySQL
Image hosting business in minutes
Send HTML mail in PHP
Send bulk emails in PHP
Polling/Rating System in PHP
Polling/Rating System in PHP(radio button)
Check visitor's IP address
Check reciprocal link
PHP tutorial
What is PHP?
Install PHP on Windows XP (part1)
Install PHP on Windows XP (part2)
PHP open and closing tags
PHP types
Variables
Constants
Operators(part1)
Operators(part2)
Logic Structures
Include files
Loops
Set cookie and delete cookie
Most often used MySQL functions

 

 

Printer Inkjet A Z lyricsLearn ChineseHome|PHP|Swing|HTML|JavaScript|ASP|JAVA|Forum|WebTip|Contact Us
Copyright © kidslovepc.com All rights reserved(new). Privacy|Copyright
designed by info@kidslovepc.com

Please help us cover the web site maintenance fee.
barcode scanner Thermal Printer credit card machine bar code printer