iceblox Posted May 24, 2007 Share Posted May 24, 2007 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 Quote Link to comment Share on other sites More sharing options...
Wildbug Posted May 24, 2007 Share Posted May 24, 2007 Read the PHP manual pages for file_get_contents() and preg_match(), plus the entire section for whatever database you have, if it's supported in PHP. Quote Link to comment Share on other sites More sharing options...
iceblox Posted May 24, 2007 Author Share Posted May 24, 2007 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? Quote Link to comment Share on other sites More sharing options...
Wildbug Posted May 24, 2007 Share Posted May 24, 2007 For one, I believe you have the order of arguments to strpos() reversed. Quote Link to comment Share on other sites More sharing options...
iceblox Posted May 24, 2007 Author Share Posted May 24, 2007 Hmm tried it the other way round, still no luck... Im sorry to be a pain im still a noob to all this. Quote Link to comment Share on other sites More sharing options...
chigley Posted May 24, 2007 Share Posted May 24, 2007 Try if(!$pos) Quote Link to comment Share on other sites More sharing options...
iceblox Posted May 24, 2007 Author Share Posted May 24, 2007 Hmm, Still no joy Quote Link to comment Share on other sites More sharing options...
Wildbug Posted May 24, 2007 Share Posted May 24, 2007 Is it confirmed that the link you seek is on the page you've loaded, and exactly the same as the search text? Quote Link to comment Share on other sites More sharing options...
Wildbug Posted May 24, 2007 Share Posted May 24, 2007 <?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. Quote Link to comment Share on other sites More sharing options...
iceblox Posted May 25, 2007 Author Share Posted May 25, 2007 Yeah still not achieving what i want it to do, i know Im on the right track though... Any body got any ideas? Quote Link to comment Share on other sites More sharing options...
Wildbug Posted May 26, 2007 Share Posted May 26, 2007 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. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 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) Quote Link to comment Share on other sites More sharing options...
iceblox Posted May 26, 2007 Author Share Posted May 26, 2007 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 Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 and WildBugs Script ? how did that not work ? (of course replacing strpos with stripos) Quote Link to comment Share on other sites More sharing options...
iceblox Posted May 26, 2007 Author Share Posted May 26, 2007 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"; ?> Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 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"; ?> Quote Link to comment Share on other sites More sharing options...
iceblox Posted May 26, 2007 Author Share Posted May 26, 2007 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 Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 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"; ?> Quote Link to comment Share on other sites More sharing options...
iceblox Posted May 26, 2007 Author Share Posted May 26, 2007 Sorted!!! Thanks so much MadTechie! You have made my day! Phil Quote Link to comment Share on other sites More sharing options...
iceblox Posted May 26, 2007 Author Share Posted May 26, 2007 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!'; } ?> Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 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 Quote Link to comment Share on other sites More sharing options...
iceblox Posted May 27, 2007 Author Share Posted May 27, 2007 Cheers Mate! Much Appreciated! Phil Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.