forked from takechi-scratch/t-cloudsystem-www
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit.php
More file actions
67 lines (53 loc) · 1.84 KB
/
submit.php
File metadata and controls
67 lines (53 loc) · 1.84 KB
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
<?php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$userName = htmlspecialchars($_POST['entry_963022265']);
$url = 'https://script.google.com/macros/s/AKfycbwC1padrK7WN0DOKsCQyrOKWIiV3fFl2MErOoPSxD6rcHR8YrEymZEJdP6Aez_uiqTe/exec';
$data = json_encode([
[
'username' => $userName,
]
]);
function generateRandomString($length = 10) {
return substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"), 0, $length);
}
function saveToJSON($username, $filename = "random.json") {
$randomKey = generateRandomString(10);
if (file_exists($filename)) {
$jsonData = json_decode(file_get_contents($filename), true);
} else {
$jsonData = [];
}
$jsonData[$username] = ["key" => $randomKey];
file_put_contents($filename, json_encode($jsonData, JSON_PRETTY_PRINT));
return $randomKey;
}
$key = saveToJSON($userName);
$_SESSION['key'] = $key;
$_SESSION['username'] = $userName;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
curl_close($ch);
// JSONファイルにデータを保存
$filePath = 'inquiry.json';
if (file_exists($filePath)) {
$existingData = json_decode(file_get_contents($filePath), true);
if (!is_array($existingData)) {
$existingData = [];
}
} else {
$existingData = [];
}
$newData = [
'entry_963022265' => $userName,
];
$existingData[] = $newData;
file_put_contents($filePath, json_encode($existingData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));;
}
header('Location: index.php#contact');
exit();
?>