0

I found this code. He saves a text file on the server I want to change it instead to have a textBox and button. Have the possibility to compose the URL Example: www.example.com/index.php?writeText=text What needs to change in this code to do this?

<html>
<body>
    <form name="form" method="post">
        <input type="text" name="text_box" size="50"/>
        <input type="submit" id="search-submit" value="submit" />
    </form>
</body>

<?php
    if(isset($_POST['text_box'])) { //only do file operations when appropriate
        $a = $_POST['text_box'];
        $myFile = "t.txt";
        $fh = fopen($myFile, 'w') or die("can't open file");
        fwrite($fh, $a);
        fclose($fh);
    }
?>

Thanks

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119

1 Answers1

0

You use GET instead of POST.

<?php
    if(isset($_GET['writeText'])) { //only do file operations when appropriate
        $a = $_GET['writeText'];
        $myFile = "t.txt";
        $fh = fopen($myFile, 'w') or die("can't open file");
        fwrite($fh, $a);
        fclose($fh);
    }
?>
Aprilsnar
  • 521
  • 1
  • 5
  • 14
  • If you were to use $_REQUEST instead of $_GET, the same code could work with a get and a post. See [this](http://stackoverflow.com/questions/1924939/php-request-vs-get-and-post) stackoverflow answer for more info. – osantos May 30 '14 at 15:33