Hi i am trying to get the request method when the URL is requested from my localhost. I have done URL rewriting so that http://localhost/API2/products.php?product_id=1 becomes http://localhost/API2/products.php/products/1 as a result $request_method=$_SERVER["REQUEST_METHOD"]; should hold GET as the method. But rather it gets zero every time.
my.htaccess file holds these url rules:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^products/?$ products.php [NC,L]
RewriteRule ^products/([0-9]+)/?$ products.php?product_id=$1 [NC,L]
My curl commands in learn.php are:
<?php
$url = 'http://localhost/API2/products';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response_json = curl_exec($ch);
curl_close($ch);
$response=json_decode($response_json, true);
?>
So when i run my curl command which is learn.php neither it presents me any data because $request_method=$_SERVER["REQUEST_METHOD"] the request method is holding zero value.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…