-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailsecret.php
65 lines (64 loc) · 1.85 KB
/
mailsecret.php
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
<?php
session_start();
define('MAILSECRET');
require('config.php');
$mode = 0; // 0:未認証; 1:失敗; 2:成功
$isOkAuth = false;
if(@$_SESSION['ms_checked'] || $isOkAuth = check()){
$mode = 2;
}
if(!$isOkAuth){
$mode = 1;
}
function check(){
if(empty($_POST['g-recaptcha-response'])){
return false;
}
$url = 'https://www.google.com/recaptcha/api/siteverify';
$args = array(
'secret' => SECRET_KEY,
'response' => $_POST['g-recaptcha-response'],
'remoteip' => $_SERVER['REMOTE_ADDR'],
);
$url = $url . '?' . http_build_query($args);
$headers = array(
'Content-Type: application/x-www-form-urlencoded',
);
$opts = array('http' =>
array(
'method' => 'GET',
'header' => implode("\r\n", $headers),
'ignore_errors' => true
)
);
$apiResponse = file_get_contents($url, false, stream_context_create($opts));
$jsonData = json_decode($apiResponse, true);
if($jsonData['success'] !== true){
return false;
}
$_SESSION['ms_checked'] = true;
return true;
}
?>
<!doctype html>
<html>
<head>
<meta name="robots" content="noindex">
<title>MailSecret</title>
<script src="https://www.google.com/recaptcha/api.js"></script>
</head>
<body>
<h1><?php if($mode == 0){echo MSG_CAPTCHA;}elseif ($mode == 1) {echo MSG_NG;}else{echo MSG_OK;}?></h1>
<?php if($mode == 0){ ?>
<form method="post">
<div class="g-recaptcha" data-sitekey="<?php echo SITE_KEY;?>"></div>
<input type="submit" value="表示">
</form>
<?php } ?>
<?php if($mode == 2){ ?>
<div>
<span>メールアドレス:</span><a href="mailto:<?php echo MAIL; ?>"><?php echo MAIL; ?></a>
</div>
<?php } ?>
</body>
</html>