Skip to content

Instantly share code, notes, and snippets.

View AndrewChamp's full-sized avatar
:octocat:
Web Application Developer / System Admin

Andrew Champ AndrewChamp

:octocat:
Web Application Developer / System Admin
View GitHub Profile
<?php
$codes = Array(
100 => 'Continue',
101 => 'Switching Protocols',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
@AndrewChamp
AndrewChamp / strip html comments.php
Created June 18, 2015 19:04
Regex for stripping HTML comments
<!--(?!<!)[^\[>].*?-->
@AndrewChamp
AndrewChamp / docx_editor.php
Created July 27, 2015 15:05
Edit a Microsoft Word .docx file using PHP and the zip extension.
<?php
/**
* Edit a Word 2007 and newer .docx file.
* Utilizes the zip extension http://php.net/manual/en/book.zip.php
* to access the document.xml file that holds the markup language for
* contents and formatting of a Word document.
*
* In this example we're replacing some token strings. Using
* the Office Open XML standard ( https://en.wikipedia.org/wiki/Office_Open_XML )
* you can add, modify, or remove content or structure of the document.
@AndrewChamp
AndrewChamp / hashing.php
Created September 29, 2015 02:50
Simple Hashing
<?php
function hasher($password, $salt){
$result = base64_encode(hash('md5', $password.$salt));
$result = substr($result, 5, -5);
return strrev($result);
}
//Example
print hasher('myPassword', time());
?>
@AndrewChamp
AndrewChamp / keygen.php
Created September 29, 2015 02:57
Random Keygen
<?php
function keygen($length='40'){
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$size = strlen($chars);
for($i = 0; $i < $length; $i++):
$str .= $chars[ rand( 0, $size - 1 ) ];
endfor;
return $str;
}
@AndrewChamp
AndrewChamp / autoloader.php
Last active December 24, 2018 06:11
PHP Autoloader - Includes files for classes that are instantiated.
<?php
spl_autoload_register(function($class){
$directorys = array(PATH.VERSION.MODULES, INSTALL.MODULES, INSTALL.THEME.'modules/');
foreach($directorys as $directory):
if(file_exists($directory.'class.'.$class.'.php')):
require($directory.'class.'.$class.'.php');
return;
endif;
endforeach;
@AndrewChamp
AndrewChamp / iframed.js
Last active December 24, 2018 06:11
iFrame'd Site
$(document).ready(function($) {
if(window.location !== window.parent.location){
$('header, footer').hide();
}
});
@AndrewChamp
AndrewChamp / domainAvailabilityChecker.php
Created December 22, 2015 20:51
Checks if a domain is available or taken.
<?php
$domain = parse_url($_GET['domain']);
$explode = array_reverse(explode('.', $domain['path']));
$dns = dns_get_record($explode['1'].'.'.$explode['0'], DNS_A);
if(count($dns) > 0):
print 'Domain Taken';
else:
print 'Domain Avaliable.';
@AndrewChamp
AndrewChamp / .htaccess-parse-html-as-php
Last active January 11, 2016 15:23
Parse html, htm, or anything you like as PHP via htaccess. cPanel compatible.
AddHandler application/x-httpd-php5 .htm .html
@AndrewChamp
AndrewChamp / .htaccess
Last active February 13, 2024 20:37
Force Port 80 or Port 443 via .htaccess. This will also remove www. from the url.
# FORCE PORT 80 (insecure / regular traffic)
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
###########################################################
#FORCE PORT 443 && REMOVE WWW. (secure / SSL)
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]