Menu DaniWeb
Log In Sign Up
  • Read
  • Contribute
  • Meet
  1. Home
  2. Programming Forum
  3. Web Development Forum
  4. Code Snippet Repository
  5. Reusable Code Snippet

(Back) link checker

19 Years Ago olaf 0 Tallied Votes 183 Views Share

This function is usefull for peoples with a link directory where the links are stored inside a (MySQL) database. The PHP script is easy to use to find out if a reciprocal link still exists on the corresponding webpage. It takes care about the trailing slash in urls and can be used with (almost) every url. Inside the function is a check against a regular expression pattern and the result is a simple boolean. Check the example here

php
<?php
function check_back_link($remote_url, $your_link) {
    $match_pattern = preg_quote(rtrim($your_link, "/"), "/");
    $found = false;
    if ($handle = @fopen($remote_url, "r")) {
        while (!feof($handle)) {
            $part = fread($handle, 1024);
            if (preg_match("/<a(.*)href=[\"']".$match_pattern.
"(\/?)[\"'](.*)>(.*)<\/a>/", $part)) {
                $found = true;
                break;
            }
        }
        fclose($handle);
    }
    return $found;
}
// example:
//if (check_back_link("http://www.all4yourwebsite.com", "http://www.finalwebsites.com")) echo "link exists";
?>
About the Author
Member Avatar for olaf
olaf 0 Newbie Poster

Web developer

Member Avatar for gezilistesi
gezilistesi 0 Newbie Poster
16 Years Ago

this is not working

You have any code for baclink checker code for my web site

Edited 15 Years Ago by Ezzaral because: n/a
Member Avatar for atess
atess 0 Newbie Poster
15 Years Ago

Unfortunately, this code does not work or I can not run

Edited 15 Years Ago by Ezzaral because: Snipped url. Please restrict such links to your site-wide user signature, which can be edited from the user control panel.
Member Avatar for magic99
magic99 0 Newbie Poster
14 Years Ago

If link exist on inner page then this code is not working

Member Avatar for Dani
Dani 4,562 The Queen of DaniWeb Administrator Featured Poster Premium Member
2 Years Ago

DaniWeb now has an official tool that does this.

Reply to this topic
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.

Sign Up — It's Free!
Related Topics
  • Member Avatar Create a sort by link (wordpress/php) 6
  • Member Avatar PHP Chat 7
  • Member Avatar Rookie having problem with 2 consecutive Ajax calls: 1st message lost 6
  • Member Avatar [PHP] is_int is false on integer? 2
  • Member Avatar Most efficient "real-time" system. Socket Server or Client Queries 5
  • Member Avatar PHP and Javascript: Javascript only runs once... 29
  • Member Avatar I want to compete with www.myspace.com (Can someone teach me how) 40
  • Member Avatar php.ini file not being read 8
  • Member Avatar Cookie cleared after browser refresh/restart 2
  • Member Avatar PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result 20
  • Member Avatar Please take a look: PHP string to variables | For each arrays 2
  • Member Avatar PHP, MySQL & ajax with data on default page 2
  • Member Avatar Preg match and replace for img urls 2
  • Member Avatar PHP - Converting IP to Country 9
  • Member Avatar Help with formating and displaying PHP and MYSQL search results. 8
  • Member Avatar PHP Script to find Visitor's Location 9
  • Member Avatar Smart Mind "FLOAT EVERYTHING" 1
  • Member Avatar php block login for 15 minutes after 3 failed attempts URGENT 7
  • Member Avatar PHP: Display Image frm Database. First Come First Serve. 2
  • Member Avatar PhP stripe images 1
Not what you need?

Reach out to all the awesome people in our web development community by starting your own topic. We equally welcome both specific questions as well as open-ended discussions.

Start New Topic
Topics Feed
Reply to this Topic
Edit Preview

Share Post

Insert Code Block

  • Forums
  • Forum Index
  • Hardware/Software
    • Recommended Topics
  • Programming
    • Recommended Topics
  • Digital Media
    • Recommended Topics
  • Community Center
    • Recommended Topics
  • Latest Content
  • Newest Topics
  • Latest Topics
  • Latest Posts
  • Latest Comments
  • Top Tags
  • Topics Feed
  • Social
  • Top Members
  • Meet People
  • Community Functions
  • DaniWeb Premium
  • Newsletter Archive
  • Markdown Syntax
  • Community Rules
  • Developer APIs
  • Connect API
  • Forum API Docs
  • Tools
  • SEO Backlink Checker
  • Legal
  • Terms of Service
  • Privacy Policy
  • FAQ
  • About Us
  • Advertise
  • Contact Us
© 2025 DaniWeb® LLC