Skip to content

Instantly share code, notes, and snippets.

Avatar

Frank Martin efarem

  • Improbable
  • London, UK
View GitHub Profile
View Force HTTPS
if (!isset($_SERVER['HTTPS']))
{
header('Status-Code: 301');
header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
}
else
{
header('Strict-Transport-Security: max-age=500');
}
@efarem
efarem / Resize Image Canvas
Created Sep 25, 2013
Quick and dirty was to resize an image canvas, center original and fill white space
View Resize Image Canvas
<?php
function processImage($imgname)
{
// Load original image
$original = @imagecreatefromjpeg($imgname);
if (!$original)
die('Bad Image: ' . $imgname);
@efarem
efarem / ISO2 Country Codes
Last active Jan 16, 2016
A function to return a PHP array of ISO2 country codes. I use this a lot for HTML selects
View ISO2 Country Codes
<?php
/**
* An array of countries with ISO2 codes as key
*
* @return array
**/
function getCountries()
{
$options["AF"] = "Afghanistan";
@efarem
efarem / Elapsed time string
Last active Dec 21, 2015
Convert a timestamp into a relative string e.g. 2 Hours ago
View Elapsed time string
<?php
/**
* Convert a timestamp into a relative string e.g. 2 Hours ago
*
* @return string
*
* @param $time Timestamp
**/
function time_elapsed($time)
@efarem
efarem / WordPress Loop Shortcode
Last active Dec 15, 2015
WordPress loop shortcode, super useful for when you're faking post type archives using pages for SEO or for adding content above and below easily.
View WordPress Loop Shortcode
<?php
if (!class_exists('FRM_Loop'))
{
class FRM_Loop
{
public function __construct()
{
add_shortcode('loop', array(&$this, 'loop_shortcode'));
}
You can’t perform that action at this time.