I have created an android app using PhoneGap (PhoneGap is a tool which supports you to create apps using the languages like HTML, CSS, and JavaScript.).
Please note that android app is an open source app. So android app code is publicly available to server. So I can't pass password, verification variable to server.
This is my code:
<script type="text/javascript">
$(document).ready(function() {
$("#insert").click(function() {
var title = $("#title").val();
var duration = $("#duration").val();
var price = $("#price").val();
var dataString = "title=" + title + "&duration=" + duration + "&price=" + price + "&insert=";
if ($.trim(title).length > 0 & $.trim(duration).length > 0 & $.trim(price).length > 0) {
$.ajax({
type: "POST",
url: "http://www.example.com/test/insert.php",
data: dataString,
crossDomain: true,
cache: false,
beforeSend: function() {
$("#insert").val('Connecting...');
},
success: function(data) {
if (data == "success") {
alert("inserted");
$("#insert").val('submit');
} else if (data == "error") {
alert("error");
}
}
});
}
return false;
});
});
</script>
This function should update the table which is on the server using http://www.example.com/test/insert.php
. It works fine without any problems when the app is installed on a android phone.
But other users could easily update my table using above function. I mean if they know the URL (http://www.example.com/test/insert.php
) they can also update my table passing necessary post requests.
How do I prevent this from happening? How could I allow accessing the page http://www.example.com/test/insert.php
limited to just my app. I mean if request are coming from my app to http://www.example.com/test/insert.php
it should work.