I use the get method to perform some operation, for example, approve, markasspam, delete, for the comment system. I know that it is very unsafe to go this route, but I cannot help. because the reason for using the $ _GET method is to execute the operation inside the page itself using PHP_SELF, and FYI I use the post method, using the flag to perform the operation.
now in order to make it a bit safe, I want to randomize a number or generate a hash or something, and then compare it, get an identifier and perform an operation
my current code is a bit like this.
<?php if($approve == 1 ) { ?> <a href="<?php echo $_SERVER['PHP_SELF']."?approve=".$id; ?>">Unapprove</a> <?php } else { ?> <a href="<?php echo $_SERVER['PHP_SELF']."?unapprove=".$id; ?>">Approve</a> <?php } ?> | <a href="<?php echo $_SERVER['PHP_SELF']."?spam=".$id; ?>">Spam</a> | <a class="edit-comments" href="edit-comments.php?id=<?php echo $id; ?>">Edit</a> | <a href="<?php echo $_SERVER['PHP_SELF']."?delete=".$id; ?>">Delete</a>
and I perform the operation using this code.
if(isset($_GET['approve'])) { $id = intval($_GET['approve']); $query = "UPDATE comments SET approve = '0' WHERE id = '$id'"; $result = mysql_query($query); } if(isset($_GET['unapprove'])) { $id = intval($_GET['unapprove']); $query = "UPDATE comments SET approve = '1' WHERE id = '$id'"; $result = mysql_query($query); } if(isset($_GET['delete'])) { $id = intval($_GET['delete']); $query = "DELETE FROM comments WHERE id = '$id'"; $result = mysql_query($query); } if(isset($_GET['spam'])) { $id = intval($_GET['spam']); $query = "UPDATE comments SET spam = '1' WHERE id = '$id'"; $result = mysql_query($query); }
instead of using approval or non-approval or deletion or spam, I want to randomize or hash these words and make it as long as possible, and then perform the operation.
How can I do it? how do you feel about this?
EDIT: Please note: only the authenticated user ie Admin will be able to perform this operation. even though it goes through system authentication I want to add more security even for the administrator. avoid experimentation or accident
the code is not accurate, it is just a sample so that you understand what I want to achieve.