Hi all, I have a link in my php file here: piece of file1.php : <a href="file2.php">Add this to DB</a> HTML: This takes me to a page where the data gets inserted into my database. file2.php : <?php // data gets inserted header("Location: file1.php"); ?> PHP: Then it gets redirected back to file1.php But when the user gets back to file1.php, he/she can click the link again. So he can insert the data a millions times into the DB. But I don't want that. I want to disable the link. I thought that JavaScript is the right language for this, but I don't know how. Is there any way to do this. Any help appreciated. Thanks in advance.
Cookies can be used server-side to disable the link by either completely removing it or change its function.
PHP will do that for you not Javascript.. you can use sessions and/or cookies.. file1.php <?php // this should be on the top of the page session_start(); ?> ..... <?php // check if is_clicked exists if(!isset($_SESSION['is_clicked']) || !isset($_COOKIE['is_clicked'])){ ?> <a href="file2.php">Add this to DB</a> <?php } ?> PHP: file2.php <?php // this should be on the top of the page session_start(); // do the data insert here... $_SESSION['is_clicked'] = 1; seetcookie('is_clicked', 1); header("Location: file1.php"); ?> PHP: this is just a quick fix for your question.. but if you use user login, you can save that value in the database because cookies and sessions do expire..