Heim  >  Fragen und Antworten  >  Hauptteil

So ändern Sie den TXT-Wert: Verwenden Sie die Umschalttaste

Ich möchte wissen, wie ich meine Datei „database.txt“ bearbeiten kann, indem ich die Schaltfläche ein- und ausschalte. Ich fange gerade erst an zu lernen und hoffe zu verstehen, wie ich es umsetzen kann.

database.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'])) {

}

?>

Dies ist eine Weiterleitung zum Aktivieren oder Deaktivieren der Seite

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粉769413355P粉769413355372 Tage vor601

Antworte allen(1)Ich werde antworten

  • P粉090087228

    P粉0900872282023-09-14 13:16:41

    我已经尝试了几次不同的方法,无法确定如果未启用,则值为“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');
    
    
    }

    Antwort
    0
  • StornierenAntwort