Elenco file PHP nella cartella:


Sorgente di es_Link.php:

<?php

$PASSWORD = "ciao";          
$FILE = "links.txt";         


if (!file_exists($FILE)) {
    file_put_contents($FILE, "www.google.com,sito per ricerche Google\n");
}


function mostra_link($file) {
    $righe = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    echo "<h3>Lista link:</h3><ul>";
    foreach ($righe as $riga) {
        $parti = explode(",", $riga, 2);
        $url = trim($parti[0]);
        $desc = isset($parti[1]) ? trim($parti[1]) : $url;
        if (strpos($url, "http") !== 0) $url = "http://" . $url;
        echo "<li><a href=\"$url\" target=\"_blank\">$desc</a> <small>($parti[0])</small></li>";
    }
    echo "</ul>";
}


if (isset($_POST["salva"]) && $_POST["password"] === $PASSWORD) {
    file_put_contents($FILE, $_POST["contenuto"]);
    echo "<p style='color:green'>File aggiornato!</p>";
}


mostra_link($FILE);


if (isset($_POST["password"]) && $_POST["password"] === $PASSWORD) {
    $contenuto = file_get_contents($FILE);
    echo "<h3>Modifica link:</h3>";
    echo "<form method='post'>";
    echo "<textarea name='contenuto' rows='10' cols='60'>$contenuto</textarea><br>";
    echo "<input type='hidden' name='password' value='$PASSWORD'>";
    echo "<input type='submit' name='salva' value='Salva'>";
    echo "</form>";
} else {
    
    echo "<h3>Accedi per modificare:</h3>";
    echo "<form method='post'>";
    echo "<input type='password' name='password' placeholder='Password'>";
    echo "<input type='submit' value='Entra'>";
    echo "</form>";
}
?>