Script PHP per Segnalare un Errore

Scritto mercoledì 7 maggio Webmaster


Se abbiamo un sito di grandi dimensioni può risultare utile avere nelle nostre pagine un collegamento che permette al visitatore di segnalarci istantaneamente un errore.
 
Quando l’utente eseguirà il form ci arriverà una notifica direttamente nella nostra casella di posta, con la pagina dalla quale è partita la segnalazione.

Sostituite le parti in grassetto con le vostre informazioni corrette.
Per vedere l’ip del vostro sito sito potete cliccare su whois.domaintools.com

Pagina send.php

<?php
$recipient = "youremail@domain.com";
$referers = array (’tuosito.it‘,’www.tuosito.it‘,’62.149.xxx.xxx‘);
function check_referer($referers) {
if (count($referers)) {
$found = false;
$temp = explode("/",getenv("HTTP_REFERER"));
$referer = $temp[2];
if ($referer=="") {$referer = $_SERVER['HTTP_REFERER'];
list($remove,$stuff)=split(’//’,$referer,2);
list($home,$stuff)=split(’/',$stuff,2);
$referer = $home;
}
for ($x=0; $x < count($referers); $x++) {
if (eregi ($referers[$x], $referer)) {
$found = true;
}
}
if ($referer =="")
$found = false;
if (!$found){
print_error("Non sei abilitato a inviare la segnalazione <b>Dominio non autorizzato.</b>");
error_log("[FormMail.php] Referente non autorizzato. (".getenv("HTTP_REFERER").")", 0);
}
return $found;
} else {
return true;
}
}
if ($referers)
check_referer($referers);
$goto_after_mail = "thanks.htm"; // this is the page which is shown after the mail is submitted
$from_mail = $_REQUEST['from_email'];
$from_name = $_REQUEST['from_name']; // use both value’s from your form
$header = "From: \"$from_name\" <$from_mail>\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/plain; charset=\"utf-8\"\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n";
$subject = "Segnalazione ERRORE alle ".date("d-m-Y"); //your mailsubject incl. current date
$page .= "Errore proveniente dalla pagina ".$_SERVER['HTTP_REFERER'];
foreach ($_REQUEST as $key => $val) {
if ($key != "from_email" && $key != "from_name") { //skip, this values are already in the header
        $body .= $key . " : " . $val . "\r\n";
}
}
if (mail("
youremail@domain.com", $subject, $page, $body, $header)) {
header("Location: ".$goto_after_mail);
}
?> 

Pagina thanks.htm

<!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>Segnalazione errore</title>
</head>
<body>
<div style="margin:0 auto; width:520px; background-color:#F0FFFF; border:1px solid #0099FF; font-size:13px; font-family:Verdana, Arial, Helvetica, sans-serif; padding:6px 6px 6px 6px;">
La segnalazione è stata inviata correttamente.<br />
Provvederemo al più presto a correggere il problema.<br /><br />
Per tornare alla pagina precedente usa la freccia &quot;Indietro&quot; del tuo Browser. <br />
</div>
</body>
</html>

Se questo post contiene link errati, errori, o riporta ad un sito non piu' attinente all'argomento invia una Segnalazione. Provvederemo a correggere il problema o a scrivere un post alternativo.

Lascia un Commento

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word