Skip to content

Instantly share code, notes, and snippets.

View MikeRogers0's full-sized avatar
🚂

Mike Rogers MikeRogers0

🚂
View GitHub Profile
@MikeRogers0
MikeRogers0 / gist:1751763
Created February 6, 2012 12:02 — forked from westonruter/gist:311373
jQuery fallback implementation of HTML5 placeholder attribute
if(!jQuery('<input PLACEHOLDER="1" />')[0].placeholder){ //Uppercase attr for IE
jQuery(':input[placeholder]').each(function(){
var $this = $(this);
if(!$this.val()){
$this.val($this.attr('placeholder'));
$this.addClass('input-placeholder');
}
}).live('focus', function(e){
var $this = $(this);
if($this.hasClass('input-placeholder')){
@MikeRogers0
MikeRogers0 / allow-from-ip
Created June 10, 2012 21:57
Blocking users via .htaccess
order allow,deny
allow from [IP here]
deny from all
@MikeRogers0
MikeRogers0 / simple-counter.php
Created June 10, 2012 22:03
Simple PHP Page View Counter
<?php # File created on 11th February 2009 by Mike Rogers (http://www.fullondesign.co.uk/).
## Start defining constants ##
define(RUN_ERRORS, TRUE); // Do you want the script to display errors? TRUE = yes you do.
define(LOG_URL, '/home/user/logs/'); // Put the location of where you want to put the logs. Make sure this is absolute
$filename = rawurlencode(base64_encode($_SERVER['PHP_SELF'])); // Takes the filename then makes it network safe.
## End defining constants ##
## Parse filename ##
$filename = LOG_URL.$filename.'.log.txt';
##
@MikeRogers0
MikeRogers0 / input-validator.php
Created June 10, 2012 22:10
Basic PHP Security
<?php
// Input must be a number
if(is_numeric($input)){
echo 'Input is a number';
} else {
echo 'Input is not a number';
}
// Input can only contain numbers and letters.
if(preg_match('/([^A-z0-9])/', $input)){
@MikeRogers0
MikeRogers0 / link_cloaker.php
Last active October 6, 2015 00:57
Link Cloaker
@MikeRogers0
MikeRogers0 / .htaccess
Created June 10, 2012 22:24
Securing publicly available folders
Options -Indexes
Options -ExecCGI
AddHandler cgi-script .php .php3 .php4 .phtml .pl .py .jsp .asp .htm .shtml .sh .cgi
<?php
echo file_get_contents('http://tinyurl.com/api-create.php?url='.'http://www.example.com/');
/* For example
http://tinyurl.com/api-create.php?url=http://www.fullondesign.co.uk/
Would return:
http://tinyurl.com/d4px9f
*/
?>
@MikeRogers0
MikeRogers0 / simple-facebook-app.php
Created June 10, 2012 22:29
Making a simple Facebook Application
<?php
# Start by Defining everything the code needs to talk to facebook. Facebook provides these when you sign up.
define(YOUR_API_KEY, '');
define(YOUR_SECRET_CODE, '');
// Include the facebook API PHP classes.
require_once('facebook.php');
// Connect to facebook
$facebook = new Facebook(YOUR_API_KEY,YOUR_SECRET_CODE);
@MikeRogers0
MikeRogers0 / simple-hit-counter.php
Created June 10, 2012 22:33
Simple hit counter
<?php # File created on 25th April 2009 by Mike Rogers (http://www.fullondesign.co.uk/).
## Start defining constants ##
define(LOG_URL, '/home/user/download_logs/'); // Put the location of where you want to put the logs. Make sure this is absolute
# $_GET['ID'] – this is the ID of the file we want. It gets the value from the URL.
## Now set the data you wish to use – this can be moved to an include if you want ##
$file[0] = 'http://www.example.com/file.pdf';
## Define the functions required to update the file.
@MikeRogers0
MikeRogers0 / .htaccess
Created June 10, 2012 22:35
Decrease loading times via .htaccess
FileETag none # Turn off eTags
<IfModule mod_expires.c> # Check that the expires module has been installed
ExpiresActive On
ExpiresDefault "access plus 10 years"
ExpiresByType image/gif "access plus 10 years"
ExpiresByType image/jpeg "access plus 10 years"
ExpiresByType image/png "access plus 10 years"
ExpiresByType text/css "access plus 10 years"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType text/javascript "access plus 10 years"