举报功能 - 快速便捷的举报违规内容
<style>
#report-button {
position: fixed;
bottom: 20px;
right: 20px;
background-color: #f44336;
color: white;
padding: 10px 20px;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
z-index: 9999;
}
#report-form {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9998;
}
#report-form .modal-content {
background-color: #fefefe;
margin: 10% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
#report-form .close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
#report-form .close:hover,
#report-form .close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<button id='report-button'>举报</button>
<pre><code><div id='report-form'>
<div class='modal-content'>
<span class='close'>×</span>
<form action='jubao.php' method='POST'>
<label for='link'>链接:</label>
<input type='text' id='link' name='link' required>
<input type='submit' value='提交'>
</form>
</div>
</div>
<script>
document.getElementById('report-button').addEventListener('click', function() {
document.getElementById('report-form').style.display = 'block';
});
document.getElementsByClassName('close')[0].addEventListener('click', function() {
document.getElementById('report-form').style.display = 'none';
});
document.getElementById('report-form').addEventListener('submit', function(e) {
e.preventDefault(); // 阻止表单默认提交行为
var link = document.getElementById('link').value;
if (link.trim() !== '') {
// 发送异步请求
var xhr = new XMLHttpRequest();
xhr.open('POST', 'jubao.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
// 显示举报成功的提示信息
alert(xhr.responseText);
}
};
xhr.send('link=' + encodeURIComponent(link));
} else {
// 显示错误信息
alert('链接不能为空');
}
});
</script>
</code></pre>
</body>
</html>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$link = $_POST['link'];
// 检查链接是否为空
if (!empty($link)) {
// 打开文件
$file = fopen('jubao.txt', 'a');
// 写入链接
fwrite($file, $link . '\n');
// 关闭文件
fclose($file);
// 显示举报成功的提示信息
echo '举报成功';
} else {
// 显示错误信息
echo '链接不能为空';
}
}
?>
原文地址: https://www.cveoy.top/t/topic/InT 著作权归作者所有。请勿转载和采集!