Skip to content

Instantly share code, notes, and snippets.

View efarem's full-sized avatar

EFAREM efarem

  • London, UK
View GitHub Profile
@efarem
efarem / Force HTTPS
Created September 30, 2013 08:57
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 September 25, 2013 18:30
Quick and dirty was to resize an image canvas, center original and fill white space
<?php
function processImage($imgname)
{
// Load original image
$original = @imagecreatefromjpeg($imgname);
if (!$original)
die('Bad Image: ' . $imgname);
@efarem
efarem / ISO2 Country Codes
Last active January 16, 2016 09:51
A function to return a PHP array of ISO2 country codes. I use this a lot for HTML selects
<?php
/**
* An array of countries with ISO2 codes as key
*
* @return array
**/
function getCountries()
{
$options["AF"] = "Afghanistan";
@efarem
efarem / Elapsed time string
Last active December 21, 2015 01:59
Convert a timestamp into a relative string e.g. 2 Hours ago
<?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 December 15, 2015 07:19
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.
<?php
if (!class_exists('FRM_Loop'))
{
class FRM_Loop
{
public function __construct()
{
add_shortcode('loop', array(&$this, 'loop_shortcode'));
}