0

I am using the php post function to add data into an HTML file. Every time i use it the data is added in the bottom of the page. How can i make it to add it on the top..??

<?php
session_start();
date_default_timezone_set('Asia/Calcutta');  
if(isset($_SESSION['name'])){
$text = $_POST['text'];

$fp = fopen("log.html", 'a');
date_default_timezone_set("India/Kolkata");
fwrite($fp, "<div class='msgln'>(".date("g:i A").") <b>".$_SESSION['name']."</b>: ".stripslashes(htmlspecialchars($text))."<br></div>");
fclose($fp);
}
?>

I Am new in coding

  • Check this answer: http://stackoverflow.com/questions/3332262/how-do-i-prepend-file-to-beginning – kennasoft Apr 27 '17 at 15:05
  • Possible duplicate of [How do I prepend file to beginning?](http://stackoverflow.com/questions/3332262/how-do-i-prepend-file-to-beginning) – shaggy Apr 27 '17 at 17:25

1 Answers1

0

You'll have to get the full content of your file, concatenate it with the new data at the beginning (new data + old data), and overwrite the file with this new content.

Marc Brillault
  • 1,902
  • 4
  • 21
  • 41