Skip to content

Instantly share code, notes, and snippets.

@nonoesp
Created October 19, 2013 18:28
Show Gist options
  • Save nonoesp/7059622 to your computer and use it in GitHub Desktop.
Save nonoesp/7059622 to your computer and use it in GitHub Desktop.
PHP key-restricted content with GET. If high security is needed it would be better to use POST.
<?php
/**
Sample to get a url variable through GET method
Example URL: ../sample.php?apikey=MY_KEY
*/
// Define the API key here
$APIKey = 'MY_KEY'; // this is the key that the app has to send on the URL
// Obtain the GET variable apikey
$getAPIKey = $_GET['apikey']; // this is the key sent by the app on the URL
// Check if keys match each other
if ($APIKey == $getAPIKey) {
// Show JSON data here.
echo "Show data.";
} else {
// Do not show JSON data.
echo "Do not show data.";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment