8 Replies Latest reply on Jun 5, 2006 11:04 AM by MikerRoo

    Reciprocal Link Checker

    Level 1
      I have seen many Reciprocal Link Checkers in ASP and PHP and none in Coldfusion. I hold all my out links in a database and would like to loop through and see who is still linking back to me. I know that this should be able to be done in Coldfusion by reading the content of a site and returning the URL , but I am not quite sure how to tackle it.

      Any code snippets to be in the right direction would be appreciated.
        • 1. Re: Reciprocal Link Checker
          Dan Bracuk Level 5
          If you describe the logic in those asp/php programs, I can tell you how to code it in in cf. So could most of the other "answerers'" in these forums.

          At least I think we can.
          • 2. Re: Reciprocal Link Checker
            MikerRoo Level 1
            Use the Google API to search for links to your site.

            Sample search: Sample Google links search

            Get the Google API at http://www.google.com/apis/.

            Coldfusion code to use the API is here: http://surfmind.com/lab/cf/google/
            • 3. Re: Reciprocal Link Checker
              Level 1
              Here is an ASP that is close to what I am looking to do


              <%@ LANGUAGE="VBScript" %>
              <%
              Option Explicit
              Response.Buffer = true

              '***************************************
              'Reciprocal Link Checker
              '***************************************



              '***************************************
              'Main code execution
              '***************************************
              '
              'The following code is executed every time the page is loaded. Functions and subroutines
              ' are at the end of the file.

              Dim blnSubmitted

              If Request.Form("cmdSubmit") <> "" Then
              blnSubmitted = true
              End If

              %>
              <HTML>
              <BODY>
              <%
              If blnSubmitted Then
              Call ShowResults()
              Else
              Call ShowForm()
              End If
              %>
              </BODY>
              </HTML>
              <%

              '****************************************
              'Functions and Subroutines
              '****************************************


              'This subroutine will display the form for users to enter in the search term and URLs
              ' they wish to search.
              Sub ShowForm()
              If Request.QueryString("err") = "1" Then
              Response.Write "<STRONG>You must enter information in both text boxes.</STRONG><BR /><BR />"
              End If
              %>
              <FORM name="Form1" action="rl_sample.asp" method="post">
              Enter text to search for:<BR />
              <TEXTAREA name="txtSearch" rows="5" cols="50"></TEXTAREA><BR />
              Enter URLs to check (one per line):<BR />
              <TEXTAREA name="txtURLs" rows="20" cols="50"></TEXTAREA><BR />
              <INPUT type="Submit" name="cmdSubmit" value="Submit" /> <INPUT type="Reset" name="cmdReset" value="Clear" />
              </FORM>

              <%
              End Sub

              'This subroutine will display the results from the form the user entered information into.
              Sub ShowResults()
              If Request.Form("txtSearch") = "" Or Request.Form("txtURLs") = "" Then
              Response.Redirect("rl_sample.asp")
              Exit Sub
              End If

              'Declare variables
              Dim i, strSearch, arrURLs, xmlWebPage, strWebPage

              'Initialize variables
              Set xmlWebPage = Server.CreateObject ("Microsoft.XMLHTTP")
              'Set xmlWebPage = Server.CreateObject("MSXML2.ServerXMLHTTP")
              strSearch = Request.Form("txtSearch")
              arrURLs = Split(Server.HTMLEncode(Request.Form("txtURLs")), vbCrLf)
              i = 0

              'Dislay results in a table.
              Response.Write "<STRONG>Results</STRONG><BR /><BR /><TABLE border=""1"" cellpadding=""3"">"

              'Iterate through the URLs provided in the txtURLs TextBox
              Do While (i <= UBound(arrURLs))
              Response.Write "<TR><TD>" & Trim(arrURLs(i)) & "</TD><TD>"

              'Get the web page and store the text in strWebPage
              On Error Resume Next
              xmlWebPage.Open "GET", Trim(arrURLs(i)), false
              xmlWebPage.Send

              If Err.number <> 0 Then
              Response.Write "Could not open the web page"
              Else
              strWebPage = xmlWebPage.ResponseText

              'Look for the search string in the Web Page
              If InStr(1, strWebPage, strSearch) > 0 Then
              Response.Write "<STRONG>Search text found</STRONG><BR />"
              Else
              Response.Write "Search text not found<BR />"
              End If
              End If

              Response.Write "</TD></TR>"
              i = i + 1
              Loop
              Response.Write "</TABLE>"

              'Clean up objects
              Set xmlWebPage = Nothing

              End Sub

              %>

              Basically it loops throught the URLs that are entered into a textarea ( list ) and tells you whether the text is on the other site or not.

              The Google API, I think is doing too much. I don't want to get all the sites that are linked to me I just want to preiodically check to make sure that the sites that are linked to me haven't deleted the link back.

              So if I could get something like this working in coldfusion, I could get it to run once a week and email me if someone has stopped linking to me.
              • 4. Re: Reciprocal Link Checker
                Dan Bracuk Level 5
                Forget the loop for a second. If the solution works for one url, you can put in a loop later.

                The task at hand, as I understand it is to take a url, www.abc.com, and see if that web page contains a link to www.xyz.com.

                I don't know if it will work, but the first thing I would try is:

                <chttp url="www.abc.com />
                <cfif cfhttp.filecontent contains "www.xzy.com">
                etc
                • 5. Re: Reciprocal Link Checker
                  MikerRoo Level 1
                  Use the attached code.

                  • 6. Re: Reciprocal Link Checker
                    Level 1
                    Hi MikerRoo,

                    Tried the code you posted and I can't seem to get it to work without errors-
                    Here are the errors -

                    Attribute validation error for tag http.
                    The tag does not have an attribute called result. The valid attribute(s) are url, port, method, username, password, name, columns, charset, path, file, delimiter, textqualifier, resolveurl, proxyserver, proxyport, proxyUser, proxyPassword, useragent, throwonerror, redirect, firstRowAsHeaders, timeout, multipart, getAsBinary.

                    ColdFusion cannot determine the line of the template that caused this error. This is often caused by an error in the exception handling subsystem.
                    • 7. Re: Reciprocal Link Checker
                      Level 1
                      Dan Bracuk 's code with the typos fixed works. So thanks Dan, I can start here to mod the app to run through my links and check them.



                      <cfhttp url=" http://www.wpxdesign.com/index.html"/>
                      <cfif cfhttp.filecontent contains ' http://www.intcommunications.com'>
                      Yes it does
                      <cfelse>
                      No it doesn't
                      </cfif>
                      • 8. Re: Reciprocal Link Checker
                        MikerRoo Level 1
                        quote:

                        Originally posted by: jimWPX
                        Hi MikerRoo,

                        Tried the code you posted and I can't seem to get it to work without errors-
                        Here are the errors -

                        Attribute validation error for tag http.
                        The tag does not have an attribute called result. The valid attribute(s) are url, port, method, username, password, name, columns, charset, path, file, delimiter, textqualifier, resolveurl, proxyserver, proxyport, proxyUser, proxyPassword, useragent, throwonerror, redirect, firstRowAsHeaders, timeout, multipart, getAsBinary.

                        ColdFusion cannot determine the line of the template that caused this error. This is often caused by an error in the exception handling subsystem.




                        You must be running an obsolete version of CF (The "result" attribute was added with CF7).
                        Comment out the "result" line and replace "sHTTP_Results" with "cfhttp" everywhere it occurs.

                        In all cases, you will eventually find that google does a far better job and is much faster and more robust.
                        You're a fool to reinvent a wooden cart wheel when a set of superb Michelin all-seasons already exists.