Skip to content

Instantly share code, notes, and snippets.

View nonsalant's full-sized avatar
💭
I may be slow to respond.

Stefan Matei nonsalant

💭
I may be slow to respond.
View GitHub Profile
@nonsalant
nonsalant / .htaccess
Last active March 28, 2022 16:10
Remove .php extension from URL's and add a trailing slash
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
@nonsalant
nonsalant / echoFromFile.php
Last active November 9, 2015 01:44
echoFromFile.php
function echoFromFile($fileName, $run, $data) {
if (!is_dir('temp')) {
mkdir('temp');
}
file_put_contents($fileName, $data);
if ($run===1) {
include($fileName);
}
else {
readfile($fileName);
@nonsalant
nonsalant / limit.php
Last active January 17, 2024 03:49
Throttling requests on a per IP basis
<?php
// https://vileworks.com/projects/limit.php
// This page can only be accessed 5 times in any 10 second interval.
function limit_requests($nr=5,$t=10) {
if (!session_id()) {
start_session_based_on_ip();
}