Jump to content

Recommended Posts

Hi Guys,

 

Another newbie after some help  ;),

 

I have links in my database and i want to write a script to able me to check that the link to my site still exsits on their site without having to manually check. But im not too sure where to start.. Can anyone point me in the right driection please? Or does anyone know which feature i need to use

Link to comment
https://forums.phpfreaks.com/topic/52825-solved-checking-reciprocal-links/
Share on other sites

Ive got this far

 

$myUrl = 'http://www.mysite.com';
$recipUrl = 'http://www.theirsite.co.uk';
$pos = strpos($myUrl, file_get_contents($recipUrl));
if($pos === false)
{
echo'link is not there';
} else {
echo'link is there';
}

 

but its not working can any one see any particular errors?

 

<?php

$testText = '<html><body>my link is in this page.  <a href="http://www.mysite.com/">My link.</a></body></html>';
$testURL = 'http://www.mysite.com';

$is_there = strpos($testText,$testURL);

if ($is_there !== false) echo "Found it @ offset $is_there!\n";

?>

 

For instance, the above works.  You might also look into stripos() to avoid case-sensitivity issues.

Yeah still not achieving what i want it to do, i know Im on the right track though... Any body got any ideas?

 

What is or isn't it doing that you want or don't want it to do?  Be more specific.  We're programmers, not psychics.

 

you sure your not psychic wildbug (coz i was just thinking that exact same thing)

Sorry guys, was slightly sleepy when i wrote that. But you guys should have known that! LoL! I am trying to get a script together that will tell me whether a link to my site exists on a third party site. Currently the scripts that are posted aren't doing this, some always say the link is always then where when there is no link present and some say there is no link when they may or may not be a link present. Does this make more sense? Any help would be gratefully appreciated.

 

Thanks, Phil

As stripos that came up with a undifined function errror and as strpos it was unable to find it.

 

But to make sure im using it right i have.

 

<?php

$testText = '<html><body>my link is in this page.  <a href="http://www.MYLINK.com/">Mobile Reviews</a></body></html>';
$testURL = 'http://www.THEIRLINK.co.uk';

$is_there = strpos($testText,$testURL);

if ($is_there !== false) echo "Found it @ offset $is_there!\n";

?>

OK as your on PHP4 try this

 

<?php

$testText = '<html><body>my link is in this page.  <a href="http://www.MYLINK.com/">Mobile Reviews</a></body></html>';
$testURL = 'http://www.THEIRLINK.co.uk';

$is_there = strpos(strtolower($testText),strtolower($testURL));

if ($is_there !== false) echo "Found it @ offset $is_there!\n";

?>

Yeah still not working. I tried it and nothing came up so out of curiosity i put the same link in each field and it found it. I have this sneaky feeling that it is only look in testtext and not the contents of that page. Or am i just being blonde?

 

By the way thanks for you help madtechie

ahhh i get you

 

try this

 

<?php
$testURL = 'http://en.www.mozilla.com/en/firefox/about/'; //link to check
$siteContents = file_get_contents("http://www.google.co.uk/firefox?client=firefox-a&rls=org.mozilla:en-GB:official"); //link to check

$is_there = strpos(strtolower($siteContents),strtolower($testURL));

if ($is_there !== false) echo "Found it @ offset $is_there!\n";

?>

MadTechie,

 

One last thing. Doesnt matter too much if you dont know how to do it as i know i have a lot of ifs in this statement but where would i add

 

 

$testURL = 'http://www.mylink.com; //link to check
$siteContents = file_get_contents("$text"); //link to check

$is_there = strpos(strtolower($siteContents),strtolower($testURL));

 

to this query with $text being row 5 in teh query..

 

<?php

$query = "SELECT * FROM links";

$result = mysql_query($query);

if (mysql_num_rows($result) > 0)
{

while($row = mysql_fetch_row($result))
{


	echo '<a target="_blank" href="' . $row['4'] . '">' . $row['3'] . '</a><br>Description: ' . $row['6'] . '<br><br>';
                if($isadmin)
	{
		echo '[ <a href=editlink&linkid=' . $row['0'] . '>Edit Link</a> l <a href=deletelinks&linkid=' . $row['0'] . '>Delete Link</a> l <a target="_blank" href=' . $row['5'] . '>Check Incoming Link</a> ]<br><br>';
if ($is_there !== false) 

{
echo'link is there';
} else {
echo'link is not there';
}
	}
}

}
else
{
echo 'No links found!';
}


?>

if Check Incoming Link is red then system couldn't find the link

 

and of course set $MyURL to your url

 

<?php

$query = "SELECT * FROM links";
$MyURL = 'http://en.www.mozilla.com/en/firefox/about/';

$result = mysql_query($query);

if (mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_row($result))
{
	echo "<a target='_blank' href='{$row['4']}'>{$row['3']}</a><br>Description: {$row['6']}<br><br>";
	if($isadmin)
	{
		$siteContents = file_get_contents($row['5']);
		$is_there = strpos(strtolower($siteContents),strtolower($MyURL));

		$syscheck ($is_there !== false)?"":" color='#FF0000'";
		echo "[ <a href=editlink&linkid={$row['0']}>Edit Link</a> 1";
		echo "<a href=deletelinks&linkid={$row['0']}>Delete Link</a> l ";
		echo "<a target='_blank' href={$row['5']}><font$syscheck>Check Incoming Link</font></a> ]";
		echo "<br><br>";

	}
}
}else{
echo 'No links found!';
}

?>

 

 

EDIT:

you may need to change

$siteContents = file_get_contents($row['5']);

to

$siteContents = file_get_contents($row['4']);

 

as i wasn't sure which one was the other sites URL

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.