0

would it be possible to have a html/php template on index.php say for example (a news webpage template and then anyone can edit the title, paragraphs only, then on submit it then sends the webpage with the data stored to a paste bin like url so who ever visits that url say http://localhost/news/jjeh3bndjks they would only be able to view to content and not edit.

I would like to use something like this

<?php
if ($_POST) {
    $pasteID = uniqid();
    $paste = fopen("pastes/".$pasteID.".php", "w");
    $contents = $_POST['pasteContents'];
    fwrite($paste, $contents);
    header('Location: /pastes/'.$pasteID.'.php');
}
?>

<form action="" method="POST">
  <input type="text" name="pasteContents" placeholder="write here" />
  <button type="submit" tabindex="0">submit</button>
</form>

but for some reason when i add another input box or try to send anymore data it fails or just gives me the last input given is there a way to send a whole page this way?

any help would be appreciated

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135

1 Answers1

0

You can use file_get_contents with the following code:

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    parse_str(file_get_contents('php://input'));
    echo param1 . '<br />' . param2;
} else {
?>

<form method="post">
    <input type="text" name="param1" value="param1" />
    <input type="text" name="param2" value="param2" />
    <input type="submit" value="submit" />
</form>
<?php } ?>

(You can test it here)

Although, I did success to use $_POST too:

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {    
    echo $_POST['param1'] . '<br />' . $_POST['param2'];
} else {
?>

<form method="post">
    <input type="text" name="param1" value="param1" />
    <input type="text" name="param2" value="param2" />
    <input type="submit" value="submit" />
</form>
<?php } ?>

Here

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135