mysql - Prevent other users from calling php file -
here have php code:
update:
<?php $pdo=new pdo("mysql:dbname=gmaestro_agro;host=localhost","gmaestro_agro","pass"); $statement=$pdo->prepare("select * stat"); $statement->execute(); $results=$statement->fetchall(pdo::fetch_assoc); $json=json_encode($results); echo $json; ?>
i call code ajax data mysql database, when go on domain http://mywebsite.com/get_json.php
code give information of database. how can prevent other users calling this, js ajax code can call it?
at least should check whether post
request made:
if ($_server['request_method'] === 'post') { // code }
that way not fill database empty entries every time page requested via get
.
your code allows anonymous posts. possible designed way, if not, should check logged-in user. use sessions that.
apart should validate individual fields, might empty others have filled before insert.
edit: can set session variable in "main" page , check variable in ajax script. way visitor have visit main page @ least once after that, ajax script requested without problems.
Comments
Post a Comment