I am a complete noob when it comes anything security, PHP, or session related but I'm curious as to why this won't work.
So let's say you have one php file that the user completes a form on, and then you POST the variables via ajax to another php file. (I understand that this isn't secure because any form made by an attacker could POST any variables to that file from another source.) But let's say you do this:
1.php
$ran = //generate randomized var
$.ajax({
url : "2.php",
type: 'POST'
//send $ran to 2.php called random
})
2.php
<?php
require '1.php';
$random = $_POST['random'];
if ($ran != $random){
die();
}
else
{
//continue...
Why won't this be safe? Is it session related?