我想知道如何通过开关按钮来编辑我的database.txt文件。我刚刚开始学习,我希望能够理解如何实现。
数据库.txt
1|on|on|on|;
setting.php
<?php
<label class="switch">
<input type="checkbox" name="switcha">
<div class="slider"></div>
</label>
if (isset($_POST['switcha'])) {
}
<label class="switch">
<input type="checkbox" name="switchb">
<div class="slider"></div>
</label>
if (isset($_POST['switchb'])) {
}
<label class="switch">
<input type="checkbox" name="switchc">
<div class="slider"></div>
</label>
if (isset($_POST['switchc'])) {
}
?>
这是为了启用或禁用页面而进行的重定向
redirection.php
<?php
$data = file_get_contents("database.txt");
$rows = explode("|", $data);
$redirectiona = $rows[1];
$redirectionb = $rows[2];
$redirectionc = $rows[3];
if($redirectiona == "on"){
header('location: 1.php');
exit();
}
if($redirectionb == "on"){
header('location: 2.php');
exit();
}
if($redirectionc == "on"){
header('location: 3.php');
exit();
}
?> Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我已经尝试了几次不同的方法,无法确定如果未启用,则值为“off”,如果启用则值为“on”。对不起,这可能看起来很简单,但我刚刚开始。
if (isset($_POST['switcha'])) { $data = file_get_contents("database.txt"); $rows = explode("|", $data); $redirectiona = $rows[1]; $redirectionb = $rows[2]; $redirectionc = $rows[3]; $content = str_replace("1|on|$redirectionb|$redirectionc|",file_get_contents($data)); saveTxt($data,$content,'w'); }