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
Let me know what you think and if you have any improvements feel free to suggest those!
-Stefan (Managing Director @ Pretty Klicks)