This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmarvel.php
44 lines (35 loc) · 1.41 KB
/
marvel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* Author: Sundeep Joseph Machado
* Website: www.sundeepmachado.com
* Purpose: Example to query Marvel API using PHP
*/
// To create a new TimeStamp
$date = new DateTime();
$timestamp=$date->getTimestamp();
//Add your keys here. It would be better if you include them from an external file in production.
$keys=<YourPrivateKey>.<YourPublicKey>;
// Add the timestamp to the keys
$string=$timestamp.$keys;
//Generate MD5 digest, also hash is faster than md5 function
$md5=hash('md5', $string);
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
// Query Iron Man by passing value in name parameter
curl_setopt($ch, CURLOPT_URL, "http://gateway.marvel.com:80/v1/public/characters?ts=$timestamp&apikey=<YourAPIKEY>&hash=$md5&name=Iron%20man");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json')
);
// grab URL and pass it to the browser
//Execute curl
$output= curl_exec($ch) or die(curl_error());
//Format JSON output
echo str_replace('\\/', '/', $output);
// close cURL resource, and free up system resources
curl_close($ch);
?>