Checking for Keys and Looking Up Values in Arrays, Restricting Files in .htaccess

Today I learned:

Checking for a key in an array

 key_exists($key, $array) 

For the Toggl Slack slash command, I’m using it to check if someone’s Toggl API key is in the array in variables.php:

 if (key_exists($user_name, $toggl_api_key_mapping) == FALSE) { 	echo ":warning: You haven't set up your Toggl API key with this command yet. Get it at the bottom of https://toggl.com/app/profile and send it  to @$your_admin_name."; } 

Notes:

  • Case sensitive. If you need it to be insensitive, use strtolower() on the $key
  • Boolean (returns TRUE or FALSE)

Looking up a key and returning a value in an array

 $array['key'] 

For the Toggl Slack slash command, I’m using it to set someone’s API key from the array in variables.php:

 $toggl_api_key = $toggl_api_key_mapping[$user_name]; 

Blocking access to files via .htaccess

If you are serving something on your webserver that you don’t want anyone else to be able to access, you can restrict access to by adding this snippet to your site’s .htaccess file:

 log.csv> 	order allow,deny 	deny from all  

If you need only a certain IP address, you can achieve this by adding allow from 0.0.0.0 (replace that number with your IP address):

 log.csv> 	order allow,deny 	allow from 0.0.0.0 	deny from all  

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: