anchorbroken-links

What can i do to find a Broken Link?


I am working on a website and the owner of the website found three broken links (through a software/tool of IBM) in the given page. I removed two broken links but there is one broken link left. I searched the whole web page but I am unable to find it.

What can I do to find that link?

Here is the code of the page:

<?php
session_start();
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Legal Aid Service Monitoring System</title>

<link href="css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery3.js"></script>
<script type="text/javascript" src="js/jquery4.js"></script>
<script type="text/javascript" src="js/jquery5.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("#login-form").validate({
        debug: false,
            rules: {

                email: {
                        required: true,
                        email: true
                    }
                },
            messages: {             
                email: "Please enter a valid email.",
                },
        });
});
  </script>
    <style type="text/css">
        label.error { width: 250px; color: red;}
    </style>
</head>
<body>
<?php
if($_POST['login'])
{
require_once("config.php");
if($_POST['user_type']=='admin')
{
    $user=mysql_real_escape_string($_POST['uname']);
    $password=md5($_POST['pwd']);
    $sql=mysql_query("select id from admin where username='$user' and password='$password'");
    $count=mysql_num_rows($sql);
    if($count>0)
    {
        $row=mysql_fetch_array($sql);
        $_SESSION['admin']=$row['id'];
        $date=date('d-m-y');
        $time_now=mktime(date('h')+0,date('i')+00,date('s'));
        $time=date('h:i:s',$time_now);
        $login=mysql_query("insert into user_login (user_id, login_date, login_time) values ('$_SESSION[admin]', '$date', '$time')");
        header('location: administrator');
    }
    else
    {
        ?>
        <script type="text/javascript"> alert('Incorrect Username and Password.');</script>
        <?php
    }
}
else if($_POST['user_type']=='advo')
{
    $user=mysql_real_escape_string($_POST['uname']);
    $password=md5($_POST['pwd']);
    $sql=mysql_query("select id, status from advocates where email='$user' and password='$password'");
    $count=mysql_num_rows($sql);
    $row=mysql_fetch_array($sql);
    if($count>0 and $row['status']=='1')
    {
        $_SESSION['advocate']=$row['id'];
        $date=date('d-m-y');
        $time_now=mktime(date('h')+0,date('i')+00,date('s'));
        $time=date('h:i:s',$time_now);
        $login=mysql_query("insert into advo_login (advo_id, login_date, login_time) values ('$_SESSION[advocate]', '$date', '$time')");
        header('location: advocate');
    }
    else
    {
        if($row['status']=='0')
        {
            ?>
            <script type="text/javascript">alert('Your account has been blocked by admin.');</script>
            <?php
        }
        else
        {
            ?>
            <script type="text/javascript">alert('Incorrect Username and Password.');</script>
            <?php
        }
    }
}
}
?>
<div class="main" id="main">
  <div id="headerbg">
    <div id="header"></div>
    </div>
    <div id="center">
        <div class="style1" id="centerright">
            <div id="centerup">
            <table width="514" border="0" align="center">
                <tr>
                    <td><h3>Welcome to Legal Aid Service Monitoring System</h3></td>
                </tr>
            </table>
            </div>
            <div id="centerdown">
                <div id="loginbg">
                <form id="login-form" name="login-form" method="post" action="">
                <table width="500" border="0" >
                <tr><td></td>
                <td height="30">
                <input type="radio" name="user_type" value="advo" checked="checked" />Advocate
                <input type="radio" name="user_type" value="admin" />Administrator
                </td>
                </tr>
                <tr>
                <td width="50"><span class="style5">Username:</span></td>
                <td width="236"><label>
                <input type="text" name="uname" class="required input" size="30" />
                </label></td>
                </tr>
                <tr>
                <td><span class="style5">Password:</span></td>
                <td><label>
                <input type="password" name="pwd" id="pwd" class="required input" size="30"/>
                </label></td>
                </tr>
                <tr>
                <td></td>
                <td><label>
                <input type="submit" class="style1loginbg" name="login" id="button" value="Login" />
                </label></td>
              </tr>
            </table>
          </form>
          </div>
        </div>       
      </div>
    </div>
  </div>
</body>
</html>

Solution

  • If you have Firebug or somekind of similar console access you could run this snippet of code on a page by page basis:

    jQuery(function(){
      var getHost = function(url){
        url = String(url);
        if ( (url.substr(0,5) == 'http:') || (url.substr(0,6) == 'https:') ) {
          return url.split('/').slice(0,3).join('/');
        }
        else {
          return null;
        }
      }
      var host = getHost(window.location);
      jQuery('a').each(function(){
        var link = $(this), href = link.attr('href'), hst = getHost(href);
        if ( hst === host || hst === null ){
          jQuery.ajax({
            url: href,
            error: function(){
             link.css('border', '5px solid red');
            }
          });
        }
        else {
          link.css('border', '5px solid purple');
          window.open( link,'_blank');
        }
      });
    });
    

    It should highlight with a red border any internal links that fail to load via ajax, and highlight any external links with purple (at which point it'll try and open the external link in a new tab for you to visually check). Obviously this might go a bit mad if your page has many external links...

    It would be far better to actually get some link checking software - search Google - and run that... as that should act in a way that's know as 'Spidering a site'. Basically it would step through each of your pages and return a report of all the broken links found (you'd have to make sure the software supported cookies seeing as the site you've given requires authorisation).

    One further thing to be aware of is that it isn't just links that can cause software to fire a 'broken link' error. You may find that some of your page resources trigger a 404... i.e. you should check all your images, css and js to make sure they load.