Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    scrivere su file txt con form

    ciao a tutti ho questo script che mi legge il contenuto di un file di testo (testo.txt) e me lo visualizza in una textarea in modo da poterlo modificare e poi tramite il tasto invia lo salvo

    1- andate qui http://www.nextart.it/public/scrivere/1.swf per vedere il contenuto del file di testo caricato in un file flash
    2- andate qui http://www.nextart.it/public/scrivere/pannello.php
    user e psw: freedemo
    e vedrete il testo comparire nelal textarea.

    3- provate a modificarlo (oppure) premete anche solo invia

    compaiono le barre e il file flash non legge piu'....

    codice:
    <?php
    $username = "freedemo";
    $password = "freedemo";
    $viaForm = (md5(@$_POST["username"]) == md5($username) && md5(@$_POST["password"]) == md5($password));
    $viaCookie = (md5(@$_COOKIE["username"]) == md5($username) && md5(@$_COOKIE["password"]) == md5($password));
    $scadenza = time()+600;
    if ($viaForm) {
    setcookie("username", $_POST["username"], $scadenza);
    setcookie("password", $_POST["password"], $scadenza);
    }
    if ($viaCookie) {
    setcookie("username", $_COOKIE["username"], $scadenza);
    setcookie("password", $_COOKIE["password"], $scadenza);
    }
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    </style>
    <title>Scrivere su un file di testo</title>
    </head>
    
    <body>
    <?php
    if ($viaForm || $viaCookie) {
    if (isset($_POST["article"])) {
    $fp = fopen("testo.txt", "w+");
    fwrite($fp, $_POST["article"]);
    fclose($fp);
    }
    $myText = file_get_contents("testo.txt");
    ?>
    <form method="post">
    <textarea name="article" cols="75" rows="10"><?php echo $myText; ?></textarea>
    <input type="submit" value="Invia" />
    </form>
    <?php
    } else {
    ?>
    <form method="post" action="">
    <label>username<input type="text" name="username" /></label>
    <label>password<input type="password" name="password" /></label>
    <input type="submit" name="Submit" value="Entra" />
    </form>
    <?php
    }
    ?>
    </body>
    </html>
    il problema e' che se cliccate su invia vedrete che inserisce le barre \ prima delle virgolette e questo mi rende poi irrecuperabile il testo da un file flash.

    perche' mi inserisce le barre? come risolvere?

    grazie a tutti..
    -Nextart.it Graphic Solutions

  2. #2
    E' un problema di configurazione del php.ini. Praticamente PHP ipotizza già che tu voglia codificare i caratteri speciali (aggiungendo la \), che altrimenti potrebbero causare problemi, ad esempio nelle query mysql. Questa stessa operazione si può eseguire con la funzione addslashes, e può venire invertita con la funzione stripslashes:
    Codice PHP:
    <?php
    $username 
    "freedemo";
    $password "freedemo";
    $viaForm = (md5(@$_POST["username"]) == md5($username) && md5(@$_POST["password"]) == md5($password));
    $viaCookie = (md5(@$_COOKIE["username"]) == md5($username) && md5(@$_COOKIE["password"]) == md5($password));
    $scadenza time()+600;
    if (
    $viaForm) {
    setcookie("username"$_POST["username"], $scadenza);
    setcookie("password"$_POST["password"], $scadenza);
    }
    if (
    $viaCookie) {
    setcookie("username"$_COOKIE["username"], $scadenza);
    setcookie("password"$_COOKIE["password"], $scadenza);
    }
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    </style>
    <title>Scrivere su un file di testo</title>
    </head>

    <body>
    <?php
    if ($viaForm || $viaCookie) {
    if (isset(
    $_POST["article"])) {
    $fp fopen("testo.txt""w+");
    fwrite($fpstripslashes($_POST["article"]));//Elimino gli slashes
    fclose($fp);
    }
    $myText file_get_contents("testo.txt");
    ?>
    <form method="post">
    <textarea name="article" cols="75" rows="10"><?php echo $myText?></textarea>
    <input type="submit" value="Invia" />
    </form>
    <?php
    } else {
    ?>
    <form method="post" action="">
    <label>username<input type="text" name="username" /></label>
    <label>password<input type="password" name="password" /></label>
    <input type="submit" name="Submit" value="Entra" />
    </form>
    <?php
    }
    ?>
    </body>
    </html>
    In alternativa, se hai accesso al php.ini, puoi impostare la direttiva magic_quotes (o un nome simile), su off.

    Spero di esserti stato utile!

  3. #3
    grazie , non e' che io sia cosi' esperto di php..... funziona alla grande!!!!!

    ciao
    maurizio
    -Nextart.it Graphic Solutions

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.