Hi I have a jquery function that uses an ajax call to send information to a php page. It sends this information using the get method. My concern for this is that what if a user goes directly to the php page and enters some get variables in the url. Whilst sensitive data is not being processed by the php script, I still want just the ajax call to be able to interact with the script and not a user (via entering the url in their browser). How can this be done?
js code
$.ajax({
type: "GET",
url: "/add.php",
data: 'id=' + itemid,
dataType: "json",
success: function (data) {
document.getElementById("name").innerHTML = data[0];
document.getElementById("desc").innerHTML = data[1];
document.getElementById("price").innerHTML = data[2];
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
php code
$output = array();
$output[0] = $itemname . " " . $_GET['id'];
$output[1] = $itemdescription;
$output[2] = $itemprice;
echo json_encode($output);
exit();
Unfortunatley I cannot use the POST method, as this clashes with some code.