I need a simple php script which checks if a page has still my link on it. (To check if the reciprocal link is still there). Can anyone help? EDITED: I have just started to learn PHP.
This is what I use, it returns an TRUE if it's there and FALSE if it's not $siteurl is site your looking at! $recip is link you are looking for. Let me know if you have any problems, it's not the prettiest thing but works pretty good. function checkRecip2($siteurl, $recip) { preg_match("/^(http:\/\/)?([^\/]+)/i",$siteurl, $hostname); //get the hostname $host = $hostname[2]; $tail = str_replace($hostname[0], "", $siteurl); for($x=0;$x<2;$x++) { $startfile = fsockopen($host, '80'); //open my page socket if ($startfile) { if(trim($tail)=="") { $page = "/"; } else { $page = $tail; } fputs($startfile, "GET ".$page." HTTP/1.0\r\nHost: ".$host."\r\n\r\n"); while(!feof($startfile)) { $indexfile .= fgets($startfile, 10240); } for ($i=0; $i<count($indexfile); $i++) { $text = $text . $indexfile[$i]; } if (eregi($recip, $indexfile)) { return true; // set true if there is a backlink } else { return false; // set false if backlink is missing } fclose($startfile); } else { echo "Oops... Can't read it anyway... "; } } return $output; } PHP:
kudos to you mate... I just got that working with my script. Thankyou It is working great. However, there is one thing I want to discuss with you. Suppose the link which I am looking for is $recip. This code returns true even if $recip is just written on the page ($siteurl), and the link to $recip is not given. I hope you get me what I am trying to say.
I do see what your saying. Give me awhile and I will make it check for an actual href tag, that should solve the problem.
yeah! it is a very powerful language..... these days I am devoting much of my time to learn PHP and also MySQL. Does anyone know of a good tutorial?
not me... i remember the last time I tried learning php online was that I needed to search many sites and kind of piece together information. I guess the best thing is to pick up a book.
Mark1, You might want to do a search. If you find nothing, post a new thread with a properly worded subject, and in the correct section. This way you get your answers, and this thread can continue (unhijacked). I'm interested in link-back checking, and want to keep it that way so I can learn me. Yeah, it's all about me, me, me..... tom
netaddict, been real busy with work here. This is just a matter of doing the regex to recognize the proper format which I am trying to make work. I will PM you when I finish it.
I' am very interested on this script too, I was posting it on other thread but didn't get much response... the code I'm using is: <?php $recip = 'http://www.domain.com'; // this is the reciprocal url... that EXACTLY must match $filename = 'links1.txt'; //File with sites where your link is suppose to be 1 per line $found = 0; $notfound = 0; function backlinkCheck($siteurl, $recip) { if ($arrText = file($siteurl)){ for ($i=0; $i<count($arrText); $i++) { $text = $text . $arrText[$i]; } if (eregi($recip, $text)) { fclose ($fd); } else { return false; // set false if cklinbak is missing fclose ($fd); } } return false; } echo '<h2>Link Checker</h2>'; echo '<p> This will check if the text '.$recip .' is found on the webpages</p><hr>'; $file_contents=file($filename); for ( $i=0; $i < sizeof($file_contents); $i++) { $line = ($file_contents[$i]); $line = trim($line); $siteurl=$line; if (backlinkCheck($siteurl, $recip)) { echo '<p>Backlink was <b>FOUND</b> on: '.$siteurl."</p>\n\n"; $found++; } else { echo '<p>Backlink was <b>NOT FOUND</b> on: '.$siteurl."</p>\n\n"; $notfound++; } } echo 'Total Found '.$found .'<br>'; echo 'Total Not Found '.$notfound .'<br>'; echo 'Total Links Checked '.($notfound+$found).'<br>'; echo 'Total Not Found '.$notfound .'<br>'; echo 'Total Links Checked '.($notfound+$found).'<br>'; ?> PHP: that code was posted originally by rederick. It works very good but I would like to know if there a way to check the whole domain to see if your link is there, the code only checks the exact given url.. anyone have any ideas.. thanks
None of those codes will work too well. First of all, its a bad idea to use a socket connection and busy up someone elses website. Second, sometimes you get 403 errors and won't exactly work well. The other one does 1 page. This code you want is much more complicated, i played around with my code but wasn't able to do it right. MAybe when i have time ill develop it a bit.
netaddict, I'm guessing you've worked this out by now but I wanted to add my 2c to the end of this. You're looking for a known URL (yours) on a known website (link partner) you dont need a fancy ereg at all. You learn nothing by copying a script so heres the logic and the functions you can use. open the page file_get_contents(YourPartnersURL.com) to return the HTML as a string. file() returns an array so a valid html link written like this <a href=" yoururl.com">link</a> would fail then eregi() the string to to look for Oh screw it, its so easy heres the code. <?php $partnersURL="www.YourPartnersURL.com"; $htmlString=file_get_contents($partnersURL); if (eregi('href=\"YourURL.com\" ', $htmlString)) { echo "'link found on $partnersURL<br>"; } ?> Code (markup): href=\"YourURL.com\" backslash allows the special character " I've not checked this so look for syntax errors!! dont use ereg() as your link partner might use yoururl.com. eregi() is case insensitive. loop through all your partners and get checked! If you want something more complicated then try a fancy ereg
As a part of an ongoing campaign to increase the Link Popularity of our client's web site I am looking for some related web sites like yours to exchange links with. I would like to request you consider linking to our site. In exchange, we will link back to your site. Please add your site. Details of my site are as follows:- Please add my link at your phone related site pr2or above: - ************************************************************** Title: - IT Outsourcing Url :- globalprompt.net/ **************************************************************** And I will post all your links at:- globalprompt.net/index.php/home/addNewLinks/ where PR is 2 very soon it will become 4 Thanks, Justin