更改TXT值的方法:使用開關按鈕
P粉769413355
P粉769413355 2023-09-13 16:52:32
0
1
597

我想知道如何透過開關按鈕來編輯我的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();
    }
?>

P粉769413355
P粉769413355

全部回覆(1)
P粉090087228

我已經嘗試了幾次不同的方法,無法確定如果未啟用,則值為“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');


}
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!