Reputation: 1031
(I am using json with PHP)
Hi i have got a url, from some web service saying:
http://www.example.com?username=$username&password=$password&fname=firstname
Now they said they i can get data with xml or json to retrieve data along with passing my username and password. And when i googled found json is better option. Now i hv done doing json and received the required data successfully.
But i can see all the javascript i hav used to fetch in view-source of page. And so is the username with password.
I am a new programmer when it comes to use json or say fetching data with REST.
Can anyone just let me know the basic idea, that will be enough for me.
Upvotes: 0
Views: 2961
Reputation: 163282
What you need to do then is get that URL with PHP. To do this, cURL is most commonly used:
$parameters = array(
'username'=>$username,
'password'=>$password,
'fname'=>$fname
);
$ch = curl_init('http://www.example.com?' . http_build_query($parameters);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
You should see the data from that URL with your code. Now, since it is JSON, we need to decode that:
print_r(json_decode($output));
You should see a PHP object, where you can access its properties as needed.
Upvotes: 2