<?php
if(isset($_POST['url']) && $_POST['url'] == ''){
    $name = $_POST[name];
    $email = $_POST[email];
    $comment = $_POST[comment] ;
    $ipaddr = $_SERVER["REMOTE_ADDR"] ;
    $frompage = $_SERVER['HTTP_REFERER']  ;
    $pathFragments = explode('/', $frompage);
    $frompage = end($pathFragments);

    include("Guestbook.inc");

    $send = 'Y';
    date_default_timezone_set('America/Chicago');
    $datetime=date("Y/m/d @ H:i:s"); //date time
 //Create an array containing the words in the message
    $MessageArray = explode(' ',$_POST['comment']);
    $fd = fopen ("words.txt", "r");                   // This will stop naughty words
    while (!feof ($fd))
        {
        $buffer = fgets($fd, 4096);
        $lines[] = rtrim($buffer);
        }
        fclose ($fd);
        foreach($MessageArray as $word){
            foreach($lines as $Spam)
            {
            if (stripos($word,$Spam) !== false )
                {
                $send = 'N';
                }
            }
        if (stripos($word,'http://') !== false )
                      {
                      $send = 'N';
                      }
                    if (stripos($word,'https://') !== false )
                     {
                     $send = 'N';
                     }
                }
        if ($send === 'Y')
        {
        $sql="INSERT INTO test(name, email, comment, datetime, ipaddr, frompage) VALUES('$name', '$email', '$comment', '$datetime', '$ipaddr', '$frompage')";
        $stmt = $conn->prepare($sql);
 	    try {
  		    $stmt->execute();
         	}
 		catch(PDOException $e)
 	    {
  		echo "ERROR" . $e;
  	    }
    $conn = null; }
    }
?>