Skip to content

Instantly share code, notes, and snippets.

@apphp
apphp / gist:85738e7374cf1e63cb16af869fa20cef
Created May 24, 2017 18:39
Blocking Right-Click in Browser with JavaScript
<script type="text/javascript">
// source: www.apphp.com/index.php?snippet=javascript-blocking-right-click
function f1() {
if(document.all) { return false; }
}
function f2(e) {
if(document.layers || (document.getElementById && document.all)) {
if(e.which==2 || e.which==3) { return false; }
}
}
<?php
// This code allows to perform a query to WhoIs service in PHP.
// Source: www.apphp.com/index.php?snippet=php-whois-query
// Special thanks to: Corne O Kelly
function whois_query($domain) {
// fix the domain name: $domain = strtolower(trim($domain));
$domain = preg_replace('/^http:\/\//i', '', $domain);
$domain = preg_replace('/^www\./i', '', $domain);
$domain = explode('/', $domain);
<?php
// This code allows to calculate the full size of a directory using PHP.
// source http://www.apphp.com/index.php?snippet=php-whois-query
// Special thanks to: Corne O Kelly
/**
* Calculate the full size of a directory
* @param string $DirectoryPath Directory path
*/
function CalcDirectorySize($DirectoryPath) {
SELECT order_id,product_name,qty FROM orders
INTO OUTFILE '/tmp/customers.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
-- source: http://www.apphp.com/index.php?snippet=mysql-create-csv-from-select
@apphp
apphp / gist:1c85d198573720a34fce
Created January 18, 2016 20:08
Turn Off Autocomplete for Input in HTML
This would be useful when a text input is one-off or unique. Like a username or email input, one-time use codes, or for when you have built your own auto-suggest/auto-complete feature and need to turn off the browser default.
<input name="email" type="text" autocomplete="off" />
<style type="text/css">
/* source: www.apphp.com/index.php?snippet=css-cross-browser-gradient */
background-color: #000;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#bbb', endColorstr='#000');
background-image: -webkit-gradient(linear, left top, left bottom, from(#bbb), to(#000));
background-image: -webkit-linear-gradient(top, #bbb, #000);
background-image: -moz-linear-gradient(top, #bbb, #000);
background-image: -ms-linear-gradient(top, #bbb, #000);
background-image: -o-linear-gradient(top, #bbb, #000);
background-image: linear-gradient(top, #bbb, #000);
<style type="text/css">
/* source: www.apphp.com/index.php?snippet=css-my-own-font */
@font-face{
font-family: 'MyFont';
src: url('myfont.eot');
src: url('myfont.eot?#iefix') format('embedded-opentype'),
url('myfont.woff') format('woff'),
url('myfont.ttf') format('truetype'),
url('myfont.svg#webfont') format('svg');
}
<script type="text/javascript">
// Source: Anti iFrame Buster in JavaScript
var prevent_bust = 0;
window.onbeforeunload = function() { prevent_bust++; }
setInterval(function() {
if (prevent_bust > 0) {
prevent_bust -= 2;
window.top.location = 'http://domain.com';
}
}, 1);
<script type="text/javascript">
// Source: http://www.apphp.com/index.php?snippet=javascript-getting-ip-address
var ip = '<!--#echo var="REMOTE_ADDR"-->';
document.write('Your IP address is: ' + ip);
</script>
<?php
// source: http://www.apphp.com/index.php?snippet=php-calculate-age-using-birth-date
function age($date){
$time = strtotime($date);
if($time === false){
return '';
}
$year_diff = '';