2

I have got the following curl code to check whether a number is DND activated or not. But i don't know how to use this. How can i implement this in php to get json output.

CURL code:

curl --get --include "https://dndcheck.p.mashape.com/index.php?mobilenos=9999999999%2C8888888888" \
  -H "X-Mashape-Key: g5Svg3wHuomshHIyjncC0hetIUVXp1h7E0LjsnJmorZlVxUcQV"

Link to api and documentation: https://www.mashape.com/blaazetech/dnd-check

1 Answers1

2

Try this and tell me how it is working for you:

<?php
// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"X-Mashape-Key: g5Svg3wHuomshHIyjncC0hetIUVXp1h7E0LjsnJmorZlVxUcQV"               
  )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$res = file_get_contents('https://dndcheck.p.mashape.com/index.php?mobilenos=9999999999%2C8888888888', false, $context);
print_r(json_decode($res, true));
?>

Hope this is enough to get you started.
In practice I guess you will have to make the key and the phone number obtained by a variables, but this is trivial.

Antoan Milkov
  • 2,152
  • 17
  • 30
  • Posting solutions without any explanation doesn't help anyone, can you please post why your code works and why did you use this approach? – Mihai Iorga Oct 24 '14 at 05:18
  • @MihaiIorga I will gladly put a lot of explanations on each and every line of the code, however this was not what OP asked about. Here is his question again: `How can i implement this in php to get json output`. Otherwise you are right - learning by example is not always the best thing ... unless we are speaking about leadership :) – Antoan Milkov Oct 24 '14 at 05:24
  • Yes, but you are not using `curl`, therefore your answer cannot be valid, if you take that as what OP asked :) – Mihai Iorga Oct 24 '14 at 05:36
  • 1
    @MihaiIorga Actually first I prepared answer with `curl` and then decided against, with hope that `file_get_contents` method will be easier to understand. Also this way the solution will work without the need to depend on curl module. But anyway for completeness I will include the curl method as well. – Antoan Milkov Oct 24 '14 at 05:43
  • @MihaiIorga want to use this for my website. It is used to check whether a mobile number is dnd activated or not (indian numbers).. –  Oct 24 '14 at 15:50