I have read many post on Stackoverflow.com on how to prevent any CSRF attack. The solution I found here seems not to be the way i want to go with it. Here is the stackoverflow.com answer from the links below for someone who is trying to delete a record while ensuring that CSRF attack is not possible.
confirm.php
<?php
session_start();
$token= md5(uniqid());
$_SESSION['delete_customer_token']= $token;
session_write_close();
?>
<html>
<body>
<form method="post" action="confirm_save.php">
<input type="hidden" name="token" value="<?php echo $token; ?>" />
Do you really want to delete?
<input type="submit" value=" Yes " />
<input type="button" value=" No " onclick="history.go(-1);" />
</form>
</body>
</html>
Then when it comes to actually deleting the record:
confirm_save.php
<?php
session_start();
$token = $_SESSION['delete_customer_token'];
unset($_SESSION['delete_customer_token']);
session_write_close();
if ($token && $_POST['token']==$token) {
// delete the record
} else {
// log potential CSRF attack.
}
?>
I do not want to use the above script since the token is passed in a hidden form won't an attacker access it by opening it with firebug. This is my own concept using users login session data $_session['uid'] and session_regenerate_id();. with the code below am I still vulnerable to CSRF attack...
<?php
Assuming user is logged in and session has been initialized..
$session_start();
//Regenerate Session Id to ensure that Session Fixation Attack is not Possible...
session_regenerate_id();
$user_session = $_session['uid'];
if (!$user_session=='') {
// update the record
} else {
// there is CSRF attack.
}
?>