Last active
September 25, 2017 13:37
-
-
Save crablab/058a3922d8da15c3ef0b96d17b8c105e to your computer and use it in GitHub Desktop.
HTM Keyword Search Engine Over Text
This file contains hidden or 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
| <?php | |
| /* | |
| NOTES: | |
| You need to buy a phone number from Nexmo and set up a webhook to call back to whereever this is hosted. | |
| You also need to a Majestic API key | |
| */ | |
| //CHANGE THESE VALUES (these keys are not live - they are included for reference) | |
| define("MAJESTIC_KEY", "E75625C6856B9607AFA4232FE77E3C9C"); | |
| define("NEXMO_KEY", "266bf1aa"); | |
| define("NEXMO_SECRET", "cadae103"); | |
| define("NEXMO_NUMBER", "44xxxxxxxxxx"); | |
| //use the GET response | |
| $response = $_GET; | |
| //make request to Majestic using the text's content | |
| $majestic = json_decode(file_get_contents("https://api.majestic.com/api/json?app_api_key=" . MAJESTIC_KEY . "&cmd=SearchByKeyword&query=" . htmlspecialchars($response['text'])), true); | |
| //make a new curl | |
| $ch = curl_init(); | |
| //Check whether Majestic returned valid results | |
| if(empty($majestic['DataTables']['Results']['Data'][0]['Item'])){ | |
| $outp = "Sorry, those keywords aren't indexed by Majestic"; | |
| } else { | |
| $outp = "1. " . $majestic['DataTables']['Results']['Data'][0]['Item'] . "\n " . $majestic['DataTables']['Results']['Data'][0]['Title'] . "\n 2. " . $majestic['DataTables']['Results']['Data'][1]['Item'] . "\n " . $majestic['DataTables']['Results']['Data'][1]['Title']; | |
| } | |
| //Set up cURL reqeust to Nexmo | |
| curl_setopt($ch, CURLOPT_URL, "https://rest.nexmo.com/sms/json"); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, "from=" . NEXMO_NUMBER . "&text=" . $outp . "&to=" . $response['msisdn'] . "&api_key=" . NEXMO_KEY . "&api_secret=" . NEXMO_SECRET); | |
| curl_setopt($ch, CURLOPT_POST, 1); | |
| //Set headers | |
| $headers = array(); | |
| $headers[] = "Content-Type: application/x-www-form-urlencoded"; | |
| curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
| //execute cURL | |
| $result = curl_exec($ch); | |
| if (curl_errno($ch)) { | |
| echo 'Error:' . curl_error($ch); | |
| } | |
| //close connection | |
| curl_close ($ch); | |
| //print for debugging | |
| print_r($result); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment