1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP script to check "link-back"

Discussion in 'PHP' started by netaddict, Apr 22, 2005.

  1. #1
    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.
     
    netaddict, Apr 22, 2005 IP
  2. palespyder

    palespyder Psycho Ninja

    Messages:
    1,254
    Likes Received:
    98
    Best Answers:
    0
    Trophy Points:
    168
    #2
    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:
     
    palespyder, Apr 22, 2005 IP
  3. netaddict

    netaddict Peon

    Messages:
    640
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.

    :)
     
    netaddict, Apr 22, 2005 IP
  4. palespyder

    palespyder Psycho Ninja

    Messages:
    1,254
    Likes Received:
    98
    Best Answers:
    0
    Trophy Points:
    168
    #4
    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.
     
    palespyder, Apr 22, 2005 IP
  5. netaddict

    netaddict Peon

    Messages:
    640
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #5
    wow, that will be great :) please let me know when you have done that.
     
    netaddict, Apr 22, 2005 IP
  6. mark1

    mark1 Peon

    Messages:
    372
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #6
    wow... i didn't know php can do this type of stuff! (note to self: implement in near future)
     
    mark1, Apr 25, 2005 IP
  7. netaddict

    netaddict Peon

    Messages:
    640
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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?
     
    netaddict, Apr 25, 2005 IP
  8. mark1

    mark1 Peon

    Messages:
    372
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #8
    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, Apr 25, 2005 IP
  9. TommyD

    TommyD Peon

    Messages:
    1,397
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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
     
    TommyD, Apr 25, 2005 IP
  10. mark1

    mark1 Peon

    Messages:
    372
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #10
    TommyD took your advice and i'll post up a new thread for everyone to see...
     
    mark1, Apr 25, 2005 IP
  11. palespyder

    palespyder Psycho Ninja

    Messages:
    1,254
    Likes Received:
    98
    Best Answers:
    0
    Trophy Points:
    168
    #11
    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.
     
    palespyder, Apr 26, 2005 IP
  12. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #12
    This is a nice little piece of code. Very handy.
     
    noppid, Apr 26, 2005 IP
  13. TheSyndicate

    TheSyndicate Prominent Member

    Messages:
    5,410
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    365
    #13
    pale spyder or any one else did you find any more codes like this?
     
    TheSyndicate, Nov 16, 2005 IP
  14. blackpepper

    blackpepper Peon

    Messages:
    68
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #14
    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.. :confused: thanks
     
    blackpepper, Nov 24, 2005 IP
  15. Entelarust

    Entelarust Peon

    Messages:
    58
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #15
    nice script!
     
    Entelarust, Nov 24, 2005 IP
  16. TheSyndicate

    TheSyndicate Prominent Member

    Messages:
    5,410
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    365
    #16
    SO has there been a new version Yet or another code?
     
    TheSyndicate, Nov 25, 2005 IP
  17. execute

    execute Peon

    Messages:
    301
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #17
    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.
     
    execute, Nov 25, 2005 IP
  18. syco

    syco Guest

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    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
     
    syco, Apr 20, 2006 IP
  19. globalprompt@gmail.com

    globalprompt@gmail.com Active Member

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #19
    I like it it works great
     
    globalprompt@gmail.com, Dec 21, 2007 IP
  20. globalprompt@gmail.com

    globalprompt@gmail.com Active Member

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #20
    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
     
    globalprompt@gmail.com, Dec 21, 2007 IP