Created
January 26, 2018 09:38
-
-
Save jeremycherfas/8a8441da39fb10a12acdf3f471f9c654 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>PHP tests</title> | |
<meta name="generator" content="BBEdit 11.6" /> | |
</head> | |
<body> | |
<h1>hard-code.php</h1> | |
<?php | |
ini_set('display_errors', 1); | |
ini_set('display_startup_errors', 1); | |
error_reporting(E_ALL); | |
// Set unchanging Known variables | |
$known['action'] = "/like/edit"; | |
$known['username'] = "Jeremy"; | |
$known['known_api_key'] = "+ebbbjbv+ialrpvv"; | |
$known['token'] = base64_encode(hash_hmac('sha256',$known['action'] ,$known['known_api_key'] , true)); | |
// This is a hard-coded link to a URL | |
$mylink = "https://www.tbray.org/ongoing/When/201x/2017/09/03/Murder-chez-Hitler"; // Clean link | |
// Show that link on screen | |
Echo "The link: $mylink<br /><br />"; | |
//Create the description | |
$mydescription = 'PESOS+from+%3Ca+href%3D%27https%3A%2F%2Fwww.reading.am%2Fp%2F4Njk%2Fhttps%3A%2F%2Fwww.tbray.org%2Fongoing%2FWhen%2F201x%2F2017%2F09%2F03%2FMurder-chez-Hitler%27%3Ereading.am%3C%2Fa%3E'; // Link to Reading.am | |
//Show the desription on screen | |
Echo "The description: $mydescription<br /><br />"; | |
//Create the important part of the curl payload | |
$mybody = ['link' => $mylink, 'description' => $mydescription]; // from sebsel | |
//Create the whole curl payload | |
$known['body'] = json_encode($mybody, JSON_UNESCAPED_SLASHES); | |
$known['headers'] = array('Accept: application/json', | |
'X-KNOWN-USERNAME: ' . $known['username'], | |
'X-KNOWN-SIGNATURE: ' .$known['token'], | |
'Content-Type: application/json', | |
'Content-Length: ' . strlen($known['body'])); | |
//Execute curl | |
$ch = curl_init(); | |
// curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookiefile"); | |
curl_setopt($ch, CURLOPT_URL, 'https://stream.jeremycherfas.net' . $known['action']); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $known['body']); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $known['headers']); | |
curl_exec ($ch); | |
curl_close ($ch); | |
//Show the body of the curl payload on screen | |
Echo "<br /><br />The value of known body:<br />"; | |
var_dump($known['body']); | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment