예제 #1
0
<?php

session_start();
function returnHome($message)
{
    $_SESSION['message'] = $message;
    header('location: ./');
}
function IsNullOrEmptyString($question)
{
    return !isset($question) || trim($question) === '';
}
if (isset($_POST['g-recaptcha-response'])) {
    require_once './recaptcha/autoload.php';
    $recaptcha = new \ReCaptcha\ReCaptcha('6Lcj4wkTAAAAAM1DLFAzfyBxE7vT_8PVPnZ-88dQ');
    $resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
    if ($resp->isSuccess()) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        if (!IsNullOrEmptyString($name) and !IsNullOrEmptyString($email) and !IsNullOrEmptyString($message)) {
            mail("*****@*****.**", "Web contact", "Name: " . $_POST['name'] . "\r\nE-mail: " . $_POST['email'] . "\r\nMessage: " . $_POST['message']);
            returnHome("Message sent successfully.");
        } else {
            returnHome("Error sending message. All fields are mandatory.");
        }
    } else {
        returnHome("Error verifying captcha. Try again later.");
    }
}
예제 #2
0
                $stmt = $dbh->exec($sql);
                returnHome();
                break;
            case 'login':
                $password = $_REQUEST['password'];
                $sql = "SELECT * FROM admin WHERE password = '******'";
                $stmt = $dbh->query($sql);
                $admin = $stmt->fetch();
                if (!$empty($admin)) {
                    $_SESSION['admin'] = true;
                }
                returnHome();
                break;
            case 'logout':
                unset($_SESSION['admin']);
                returnHome();
                break;
        }
    }
    $sql = 'SELECT * FROM message ORDER BY created DESC';
    $messages = $dbh->query($sql);
} catch (PDOException $e) {
    echo $e->getMessage();
    exit;
}
?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>Guestbook</title>