Let say client side making the first call the my API . How I process the first API call? How should I intercept the http://www.mycom.com/api/GET?name=simple call inside api.php?
client.php
<?php
$ch = curl_init();
$url = 'http://www.mycom.com/api/GET?name=simple';
curl_setopt($ch, CURLOPT_GET, true);
curl_setopt($ch, CURLOPT_URL, $url);
$json = curl_exec($ch);
echo "\n".$json."\n";
?>
api.php what's inside?
<?php开发者_StackOverflow中文版
?>
try adding the following to your .htaccess file
RewriteEngine On
RewriteRule ^api/([a-zA-Z]+) api.php?mode=$1 [QSA]
when a client calls "api/GET?name=simple" this would be the same as "api.php?mode=GET&name=simple".
I think that you mean the client deal with: http://www.mycom.com/api.php?name=simple
then, the standard way is to make deal with the client, like to tell hem that the first api call must say that it is the first: http://www.mycom.com/api.php?name=simple&first
then you can know the first call in api.php
if (isset($_GET['first'])){
// first call
} else {
// not first call
}
otherwise, if you don't trust user (client), and think that he may do some bad things, you can know that it was the first api call by his IP.
精彩评论