Skip to content

Instantly share code, notes, and snippets.

View stefanpejcic's full-sized avatar
:octocat:
Live long and may the source be with you

Stefan Pejcic stefanpejcic

:octocat:
Live long and may the source be with you
View GitHub Profile
@stefanpejcic
stefanpejcic / .htaccess
Created August 29, 2019 11:20
image hotlink redirect
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
@stefanpejcic
stefanpejcic / .htaccess
Created August 29, 2019 11:28
disable php execution
<Files *.php>
deny from all
</Files>
@stefanpejcic
stefanpejcic / .htaccess
Created August 29, 2019 11:29
block IP address
<Limit GET POST>
order allow,deny
deny from 123.456.78.9
allow from all
</Limit>
@stefanpejcic
stefanpejcic / .htaccess
Created August 29, 2019 11:30
deny certain files
<files your-file-name.txt>
order allow,deny
deny from all
</files>
@stefanpejcic
stefanpejcic / .htaccess
Created August 29, 2019 11:34
wp-admin password
AuthName "Admins Only"
AuthUserFile /home/yourdirectory/.htpasswds/public_html/wp-admin/passwd
AuthGroupFile /dev/null
AuthType basic
require user putyourusernamehere
<Files admin-ajax.php>
Order allow,deny
Allow from all
Satisfy any
</Files>
@stefanpejcic
stefanpejcic / .htaccess
Created August 29, 2019 11:36
block author scan
# BEGIN block author scans
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} (author=\d+) [NC]
RewriteRule .* - [F]
# END block author scans
@stefanpejcic
stefanpejcic / .htaccess
Created August 29, 2019 11:41
block bad bots
SetEnvIfNoCase User-Agent ([a-z0-9]{2000}) bad_bot
SetEnvIfNoCase User-Agent (archive.org|binlar|casper|checkpriv|choppy|clshttp|cmsworld|diavol|dotbot|extract|feedfinder|flicky|g00g1e|harvest|heritrix|httrack|kmccrew|loader|miner|nikto|nutch|planetwork|postrank|purebot|pycurl|python|seekerspider|siclab|skygrid|sqlmap|sucker|turnit|vikspider|winhttp|xxxyy|youda|zmeu|zune) bad_bot
Order Allow,Deny
Allow from All
Deny from env=bad_bot
@stefanpejcic
stefanpejcic / .htaccess
Created August 29, 2019 11:43
disable xmr-rpc
<Files xmlrpc.php>
order deny,allow
deny from all
</Files>
@stefanpejcic
stefanpejcic / .htaccess
Created August 29, 2019 11:47
brute-force disable
RewriteEngine on
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{HTTP_REFERER} !^http://(.*)?example\.com [NC]
RewriteCond %{REQUEST_URI} ^(.*)?wp-login\.php(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$
RewriteRule ^(.*)$ - [F]
@stefanpejcic
stefanpejcic / functions.php
Created August 30, 2019 21:24
post views
function wporb_get_post_view() {
$count = get_post_meta( get_the_ID(), 'post_views_count', true );
return "$count views";
}
function wporb_set_post_view() {
$key = 'post_views_count';
$post_id = get_the_ID();
$count = (int) get_post_meta( $post_id, $key, true );
$count++;
update_post_meta( $post_id, $key, $count );