jquery - AJAX and PHP communication : the safe way -
as discussed in 1 of previous topics, i'm trying send json , php script. currently, working well. i've organized php script gets parameter in url , based on (with of switch statement) call appropriate functions. however, i've noted looking @ source, 1 can copy link php script , manipulate data through it. that's i'm not comfortable with. alternatives?
sample of .html ajax call:
function getalldata(){ $.ajax({ type: "post", url: "datadao.php?f=getall", datatype: "json", async: false, success: function(data){ $.each(json.parse(data), function(index, value) { alert(value['firstname'] ); }); }, error: function(err){ alert('error!' + json.stringify(err)); } }); }
sample of php code
switch($_get['f']) { case 'getall': $result = getall(); break; case 'getone': $id = $_get['id']; $result = getone($id); break; case 'addto': $result = addtoarray(); default: }
there aren't alternatives. public facing interface http server, not javascript. must implement whatever input sanity checking, data escaping, authentication , authorization need @ server level.
Comments
Post a Comment