I have my code to display information from a text file already:
$myFile = "file.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo $theData;
But I can’t figure out a way to make the above not show until a button is clicked. I tried making it a function but I suppose I wasn’t doing it right. I also tried using a submit button that set a cookie and once the cookie was set it displayed the above, but it didn’t work either. Are there any other methods to do this? It seems pretty easy, I just can’t quite get it to work properly.
Edit: I want to have this all done on one page, no redirecting to another page.
It seems that you dont need to necessarily read the file on the triggered action of clicking a button. If you are already reading the file, load it into a hidden HTML element, like a
<div>, then use Javascript to show that on the click of the button.PHP:
HTML Link:
<a href="#" onclick="show_content()">Show it!</a>Javascript:
Although if you are trying to read data dynamically based on what you click, that has to be done via AJAX as mentioned before.