custem-errors-logger-met-mysql-en-admin

Gesponsorde koppelingen

PHP script bestanden

  1. custem-errors-logger-met-mysql-en-admin

« Lees de omschrijving en reacties

======================
#--> De sql, run deze even in phpmyadmin om de table aan te maken waar de errors in opgeslagen kunnen worden
======================

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
CREATE TABLE `errors` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `error` varchar(8) NOT NULL default '',
  `request` varchar(64) NOT NULL default '',
  `reffer` varchar(255) NOT NULL default '',
  `date` int(10) NOT NULL default '0',
  `ip` varchar(16) NOT NULL default '',
  `agent` varchar(128) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;








======================
#--> zet dit in de .htaccess of als nog niet bestaat maak um even aan.
======================

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
ErrorDocument 400 /errors/error.php?error=400
ErrorDocument 401 /errors/error.php?error=401
ErrorDocument 403 /errors/error.php?error=403
ErrorDocument 404 /errors/error.php?error=404
ErrorDocument 408 /errors/error.php?error=408
ErrorDocument 500 /errors/error.php?error=500
ErrorDocument 503 /errors/error.php?error=503







======================
#--> de custem error page (maak een folder 'errors' in de webroot van je server aan en zet deze file erin, met de opmaak van je HTML kan je doen wat je wil
======================

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php

/********
*    Array-tje met de errors (hd = header, dc = description)
********/


$errors['400']['hd'] = 'Bad Request';
$errors['400']['dc'] = 'The server did not understand the request';

$errors['401']['hd'] = 'Unauthorized';
$errors['401']['dc'] = 'The requested page needs a username and a password';

$errors['403']['hd'] = 'Forbidden';
$errors['403']['dc'] = 'You are unauthorized to access this page';

$errors['404']['hd'] = 'File Not found';
$errors['404']['dc'] = 'The requested page could not be found';

$errors['408']['hd'] = 'Request Timeout';
$errors['408']['dc'] = 'The request took longer than the server was prepared to wait';

$errors['500']['hd'] = 'Internal Server Error';
$errors['500']['dc'] = 'The request was not completed. The server met an unexpected condition';

$errors['503']['hd'] = 'Service Unavailable';
$errors['503']['dc'] = 'The request was not completed. The server is temporarily overloading or down';

$errors['?']['hd'] = 'Undefined Error';
$errors['?']['dc'] = 'The Server could not compleet your request, The Error was undefined';



$error = isset($_GET['error']) && array_key_exists($_GET['error'], $errors) ? $_GET['error'] : '?';
$reffer = isset($_SERVER['HTTP_REFERER']) ? addslashes($_SERVER['HTTP_REFERER']) : "none";


/********
*    Connecten met mysql en de error in de db gooien
********/

@mysql_connect("localhost", "***", "***");
@
mysql_select_db("***");
@
mysql_query
(
    "INSERT INTO
        `errors`
    SET
        `error`='"
.$error."',
        `reffer`='"
.$reffer."',
        `request`='"
.addslashes($_SERVER['REQUEST_URI'])."',
        `date`='"
.time()."',
        `ip`='"
.$_SERVER['REMOTE_ADDR']."',
        `agent`='"
.addslashes($_SERVER['HTTP_USER_AGENT'])."'"
);
        

/********
*    Let's output some HTML
********/

?>
<!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=iso-8859-1" />
<title><?php echo $error; ?> Error</title>
<style type="text/css">
body {
    font-family:Tahoma, Arial, Helvetica, sans-serif;
    color:#999;
    font-size:12px;
    text-align:center;
}
div {
    margin:0px auto;
    margin-top:100px;
    text-align:left;
    text-align:justify;
    width:380px;
}
h1 {
    font-family:Tahoma, Arial, Helvetica, sans-serif;
    padding:0px;
    margin:0px 0px 20px 0px;
    font-size:28px;
    font-weight:bold;
    color:#f00;
    font-style:italic;
}
h1 span {
    color:#336699;
}
a {
    color:#999;
    text-decoration:none;
}
a:hover {
    color:#00f;
    text-decoration:underline;
}
</style>
</head>
<body>
<div>
    <?php
        echo '<h1 class="error">'.$error.' Error: <span>'.$errors[$error]['hd'].'</span></h1>'.$errors[$error]['dc'];
    ?>

</div>
</body>
</html>







======================
#-> de admin van je errorlogger, kan je neerzetten waar je wil, in je admin panel inbouwen of noem maar op, doe er wat geks mee :)
======================

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php

/********
*    Top HTML
********/

function top_html()
{

    return '<!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=iso-8859-1" />
    <title>Errors Log</title>
    <style type="text/css">
    body, table, th, td {
        font-family:Tahoma;
        font-size:11px;
    }
    a {
        color:#00f;
        text-decoration:none;
    }
    </style>
    </head>
    <body>'
;    
}



/********
*    Connecten met mysql en data pakken
********/

@mysql_connect("localhost", "***", "***");
@
mysql_select_db("***");
$res = @mysql_query("SELECT * FROM `errors` ORDER BY `id` DESC");


/********
*    Hier data laten zien als er is of table legen als op knop is geklikt
********/
    
if(mysql_num_rows($res))
{

    if(!isset($_POST['submit']))
    {

        echo top_html();
        echo '<table cellpadding="8" cellspacing="0" border="1"><tr><th>Error</th><th>Requested url</th><th>Reffer</th><th>Agent</th><th>IP</th><th>Date</th></tr>';
        
        while($data = mysql_fetch_assoc($res))
        {

            echo '<tr style="background-color:'.($data['reffer'] != 'none' ? '#FFFDD9' : '#f4f4ff"').';">
                    <td><strong style="color:#369;">'
.$data['error'].'</strong></td>
                    <td>'
.$data['request'].'</td>
                    <td>'
.($data['reffer'] == 'none' ? '&nbsp;' : '<a href="'.$data['reffer'].'" title="'.$data['reffer'].'" target="_blank">Reffer</a>').'</td>
                    <td>'
.$data['agent'].'</td>
                    <td>'
.$data['ip'].'</td>
                    <td>'
.date("d-m-Y - H:i:s a", $data['date']).'</td>
                  </tr>'
;
        }

        
        echo '</table><form action="error.php" method="post">
                <input type="submit" name="submit" value="Empty Table" />
              </form>'
;
    }

    else
    {
        @
mysql_query("TRUNCATE TABLE `errors`") or die(mysql_error());

        echo top_html();
        echo '<strong>Records Deleted!!</strong><br /><br /><a href="error.php" title="Go back">go back</a>';
    }
}

else
{
    echo top_html();
    echo 'Geen errors detected';
}


echo '</body></html>';

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.