php - How to make sure AJAX is called by JavaScript? -


i asked similar question before, , answer simply:

if javascript can it, client can it.

but still want find out way restrict ajax calls javascript.

the reason :

i'm building web application, when user clicks on image, tagged this:

<img src='src.jpg' data-id='42'/>

javascript calls php page this:

$.ajax("action.php?action=click&id=42"); 

then action.php inserts rows in database.

but i'm afraid users can automate entries "clicks" id's , such, calling necessary url's, since visible in source code.

how can prevent such thing, , make sure works on click, , not calling url browser tab?

p.s.

i think possible solution using encryption, generate key on user visit, , call action page key, or hash/md5sum/whatever of it. think can done without transforming security problem. right ? moreover, i'm not sure method solution, since don't know kind of security, or it's implementation.

i'm not sure there 100% secure answer. combination of server generated token inserted hidden form element , anti-automation techniques limiting number of requests on time period best thing can come with.

[edit] solution use captchas


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -