Free PHP Script to Check if a Link Exists on a Website Page / URL

Robot - Bot - ScraperHowdy!

So the other day I was doing some planning for developing an open API, more info coming on that soon… However, one of the things we needed to do was check if a link existed on a specific website page or URL. Seeing as we use PHP and so the APi will be built on this I realised that I would need to build this functionality first and foremost. So a quick Google and it didn’t look like anything simple existed for this!.. Time to crack open Sublime Text!

Checking For A Link Should Be Kept Simple… So Here It Is

Today I decided to use our internal PK (Pretty Klicks) progression session to create a simple script to achieve this without making it complicated. This way we can let anyone benefit from it and we can build on top of it when we need to.

How the link checker script works

In short: You input the URL (URL 1) to the web page or website you want to check for the link, you also input the domain or exact URL (URL 2) you want to check to see if it’s been linked from (in it’s HTML) on URL 1. This is done simply by pulling the HTML from the page at URL 1 and then parsing it to get all anchors and then checking them against the link we’re checking for URL 2 and if it’s there we return true or if not, false.


Fork It On Github

I decided to release this via Github to make it nice an open for you all to see. We’re releasing it via the MIT License so it’s free to use but you must attribute it back to us – it’s free after all 🙂

Download it on Github

Let me know what you think and if you have any improvements feel free to suggest those!


-Stefan (Managing Director @ Pretty Klicks)

Posted in Free Resources, Tips & Tricks | 5 Comments
By |

It's not wise to rely on DomDocument. If the HTML is malformed, it will raise an error. It's better to use regexp for parsing links.

prettyklicks moderator

@janusz2 Agreed, however also talking of well formed HTML, if it doesn't validate or if the link we're looking for is broken or not formed correctly then the chances are the link won't work as well and in terms of SEO won't pass any linking benefits to the target website / domain.

However you're welcome to fork the repository and suggest an improvement we could even list both versions!



RSS Feed
Keep up to date with our latest posts.

Learn more about making the most of your website, marketing and seo. It takes two seconds to subscribe to our rss feed.
You can get in contact with us via phone or e-mail, we will get back to you very promptly.

+44 (0)131 344 4522

Join our mailing list to find out about our free giveaways and tutorials. It's free.

Copyright © 2005 - 2020 Pretty Klicks Ltd (