I have a page with code…
<script language="JavaScript">
var link = "<img src='http://www.mysite.com/file.php?var1=firstName&var2=lastName&var3=phone'>";
document.write(link);
</script>
And I have a “file.php” gets these variables…
$firstName = $_GET['var1'];
$lastName = $_GET['var2'];
$phone = $_GET['var3'];
The problem is… I want to make it safer from refreshing the page. Because these variables are adding into the database. And if you will click “Refresh” in browser with the link from JavaScript, they are adding twice. I think, the best way to use the “POST”. How to do that correctly?
Well the way you have your code sort of sets it up for this issue. The best ‘solution’ I can think of is a catch on reload:
Beyond that the only other ‘safe’ method is to set a variable to check if the information has been sent to the server already, or a block on the server-side to prevent multiple writing.
To address your edit:
You may want to think about a submission via AJAX. You could submit to your handler and get a response back. Then it would be possible to store that (localStorage or Cookies) to prevent it from being submitted again.