Skip to content

Instantly share code, notes, and snippets.

View MikeRogers0's full-sized avatar
๐Ÿš‚

Mike Rogers MikeRogers0

๐Ÿš‚
View GitHub Profile
@MikeRogers0
MikeRogers0 / conditional-comments.html
Created June 10, 2012 22:51
Conditional Comments
<!โ€“[if IE]>
This will only show for Internet Explorer (IE)
<![endif]โ€“>
<!โ€“[if !IE]>
This will only show if the client is not using IE.
<!โ€“[endif]>
<![if IE 6]โ€“>
Only shows on IE6
<!โ€“[endif]>
<![if lte IE 6]โ€“>
@MikeRogers0
MikeRogers0 / braces.php
Created June 10, 2012 22:38
Braces Example
<?php
/* Examples of annoying code */
if ( $coder === 'Silly' ) bang_head();
while ( $coder === 'Silly' )
bang_head();
endwhile;
/* Examples of good code*/
if ( $coder !== 'Silly' ){ Drink_Beer(); }
@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"
@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 / 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);
<?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 / .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
@MikeRogers0
MikeRogers0 / link_cloaker.php
Last active October 6, 2015 00:57
Link Cloaker
@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 / 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';
##