0

So I am probably making api system and I am trying to get the client req api. I checked some tutorials and I found I could use :

$data = $_SERVER['QUERY_STRING'];

It's works but I am getting string like : action=get&id=theapikeygoeshere. And I need to get only the text after id= , How can I do that?
Thanks!

Suraj Rao
  • 28,850
  • 10
  • 94
  • 99
Plugin4U
  • 1
  • 4

3 Answers3

0

parse the query string using parse_str:

<?php

$arr = array();
parse_str('action=get&id=theapikeygoeshere', $arr);
print_r($arr);

?>

This gives:

Array
(
    [action] => get
    [id] => theapikeygoeshere
)
ewcz
  • 12,064
  • 1
  • 21
  • 44
0

You can do so by using $_GET['id']. :) $_GET can be used for any URL parameters like those.

Asperitas
  • 339
  • 5
  • 13
0

I think the best thing is to use $_GET['id'] but if you want to extract any thing from the QUERY_STRING use

parse_str($_SERVER["QUERY_STRING"], $output);
var_dump($output["id"]);
Moustafa Elkady
  • 649
  • 1
  • 7
  • 17
  • _"but if you want to extract any thing from the QUERY_STRING"_... that's what `$_GET` does. That code basically just building your own `$_GET`-array, which doesn't make much sense. – M. Eriksson Mar 18 '17 at 11:21
  • @MagnusEriksson This is what I just did. Thanks!! – Plugin4U Mar 18 '17 at 11:24