网站举报功能实现 - 如何在网页中添加举报按钮
<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';
});
</script>
</code></pre>
</body>
</html>
<p>你可以使用以下代码将表单中的链接提交到本地的jubao.txt文件中,并在提交成功后显示举报成功的提示信息。</p>
<pre><code class="language-php"><?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 '链接不能为空';
}
}
?>
</code></pre>
<p>将以上代码保存为jubao.php文件,然后将form标签的action属性改为'jubao.php',即可实现将链接提交到jubao.txt文件中,并在提交成功后显示举报成功的提示信息。</p>
原文地址: http://www.cveoy.top/t/topic/IrL 著作权归作者所有。请勿转载和采集!