0

I am attempting to post a keyword to a url and then get the json results back. This is my code for the php:

$url = 'http://www.hiddendomain.com/tld';
$fields = array( 'keyword' => urlencode('referralcode') );

foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

$result = curl_exec($ch);
$test = json_decode($result);

//close connection
curl_close($ch);

The intended results from what I can tell is supposed to return json encoded data. But when I attempt to decode it I just get a value of 1, and not the actual data.

Here's the actual response I get back

 [{"domain":"referralcode.com","status":"taken","tld":"com","url":"http:\/\/referralcode.com"},{"domain":"referralcode.co.uk","status":"taken","tld":"co.uk","url":"http:\/\/referralcode.co.uk"},{"domain":"referralcode.net","status":"taken","tld":"net","url":"http:\/\/referralcode.net"},{"domain":"referralcode.eu","status":"available","tld":"eu","url":"https:\/\/www.uniteddomains.com\/domain\/namecheck?et_cid=2\u0026et_lid=2\u0026domain=referralcode.eu"},{"domain":"referralcode.org","status":"available","tld":"org","url":"https:\/\/www.uniteddomains.com\/domain\/namecheck?et_cid=2\u0026et_lid=2\u0026domain=referralcode.org"},{"domain":"referralcode.me","status":"available","tld":"me","url":"https:\/\/www.uniteddomains.com\/domain\/namecheck?et_cid=2\u0026et_lid=2\u0026domain=referralcode.me"},{"domain":"referralcode.us","status":"available","tld":"us","url":"https:\/\/www.uniteddomains.com\/domain\/namecheck?et_cid=2\u0026et_lid=2\u0026domain=referralcode.us"},{"domain":"referralcode.co","status":"taken","tld":"co","url":"http:\/\/referralcode.co"},{"domain":"referralcode.ca","status":"available","tld":"ca","url":"https:\/\/www.uniteddomains.com\/domain\/namecheck?et_cid=2\u0026et_lid=2\u0026domain=referralcode.ca"},{"domain":"referralcode.info","status":"available","tld":"info","url":"https:\/\/www.uniteddomains.com\/domain\/namecheck?et_cid=2\u0026et_lid=2\u0026domain=referralcode.info"},{"domain":"referralcode.de","status":"available","tld":"de","url":"https:\/\/www.uniteddomains.com\/domain\/namecheck?et_cid=2\u0026et_lid=2\u0026domain=referralcode.de"},{"domain":"referralcode.tv","status":"available","tld":"tv","url":"https:\/\/www.uniteddomains.com\/domain\/namecheck?et_cid=2\u0026et_lid=2\u0026domain=referralcode.tv"}]

Am I missing something in regards to the normal process of json decoding or is this just a strange result?

1 Answer 1

2

Setting:

 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

does the trick. Sorry about that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.