homepage Welcome to WebmasterWorld Guest from 54.226.206.205
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
reciprocal link checker
a sample code or hints please
webon




msg:1275523
 10:43 pm on Nov 2, 2004 (gmt 0)

Hello Everyone,

I am coding the reciprocal link exchange form which there is function to check if my site info and link already been add on the partner site page or not.

Please anyone who works on similar function gives me a hint how it works or any sample code would be a great appreciation.

Thanks in advance.

webon

 

mincklerstraat




msg:1275524
 10:03 am on Nov 3, 2004 (gmt 0)

try using
file_get_contents() to load up the page that the user designates as the one where they've added your url, and then strpos() or preg_match() (more difficult, but able to find links if they've done weird stuff like <a class="links" href="ht*p://yoursite.com">, or if they've used single quotes - though this doesn't happen so much - you could always put a note on an error page explaining this).

$myurl = 'ht*p://www.mysite.com';
$checkhtml = file_get_contents($submittedurl);
if(preg_match('#<a[^>]*href[\s]*=[\s]*['"]?'.$myurl.'#', $checkhtml)) {
echo 'thanks for the link!';
/* do your processing stuff */
} else {
echo 'freeloader #(}@!';
/* do your error stuff */
}

the line with 'preg_match' might not work - I have to correct my regexes all the time - if not, a simple
strpos() will work, though more limited, but if you don't understand regexes, it has the extra benefit of being easily understandable. So if this doesn't work, replace the preg_match line with this:
if(strpos($myurl, $checkhtml)!== false) {
Note that this won't find javascript links, or redirect links, common in directories. This could also go on your error page - that the link needs to be an ordinary HTML link.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved