Skip to content

Instantly share code, notes, and snippets.

@apphp-snippets
apphp-snippets / Alternating Table Color Rows in CSS
Created February 11, 2013 08:40
These 2 techniques can be used for alternating row-colors in a table.
<!-- source: http://www.apphp.com/index.php?snippet=css-alternating-table-color-rows -->
<style type="text/css">
/* technique 1 */
tbody tr:nth-child(odd){ background-color:#ccc; }
/* technique 2 */
TBODY TR.odd { background-color:#78a5d1; }
</style>
<table>
<tbody>
@apphp-snippets
apphp-snippets / Redirect with a Dropdown Menu in JavaScript
Created February 11, 2013 08:39
This simple scripts show a possibility to call a JavaScript function that retrieves a variable passed from drop down box as a parameter and then the JavaScript redirects the browser to the variable that was passed to it.
<script type="text/javascript">
function do_redirect(site){
window.location.href = site;
}
</script>
<select onchange="do_redirect(this.value)">
<option value="#">What site would you like to see?</option>
<option value="http://www.google.com">Google</option>
<option value="http://www.yahoo.com">Yahoo</option>
@apphp-snippets
apphp-snippets / Specify Referring Page in JavaScript
Created February 11, 2013 08:38
This script informs your visitor that a given page may be reached only from the page that you specify. Paste this code before the ending <head> tag on the page:
<!-- source: http://www.apphp.com/index.php?snippet=javascript-specify-referring-page -->
<script type="text/javascript">
var allowed_referrer = "http://www.yourdomain.com/referring_page_name.html";
if(document.referrer.indexOf(allowed_referrer) == -1){
alert("You can access this page only from " + allowed_referrer);
window.location = allowed_referrer;
}
</script>
@apphp-snippets
apphp-snippets / Doing POST Request by Socket Connection
Created February 11, 2013 08:36
Doing POST Request by Socket Connection
<?php
// source: http://www.apphp.com/index.php?snippet=php-post-request-by-socket-connection
// submit these variables to the server
$post_data = array("test"=>"yes", "passed"=>"yes", "id"=>"3");
// send a request to specified server
$result = do_post_request("http://www.example.com/", $post_data);
if($result["status"] == "ok"){
// headers
echo $result["header"];
@apphp-snippets
apphp-snippets / Using Gravatars In Your Script
Last active December 12, 2015 09:39
Using Gravatars In Your Script
<?php
// source: http://www.apphp.com/index.php?snippet=php-using-gravatars-in-your-script
function show_my_gravatar($email, $size, $default, $rating)
{
$params = '?gravatar_id='.md5($email).'&default='.$default.'&size='.$size.'&rating='.$rating;
$output = '<img src="http://www.gravatar.com/avatar.php'.$params.'" width="'.$size.'px" height="'.$size.'px" />';
echo $output;
}
?>
<?php
// source: http://www.apphp.com/index.php?snippet=php-compress-multiple-css-files
header('Content-type: text/css');
ob_start('compress_css');
function compress_css($buffer) {
/* remove comments in css file */
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
/* also remove tabs, spaces, newlines, etc. */
$buffer = str_replace(array("\r", "\n", "\r\n", "\t", ' ', ' ', ' '), '', $buffer);
@apphp-snippets
apphp-snippets / gist:4013562
Created November 4, 2012 20:24
This definition allows redirection to the provided URL in 5 seconds. You may set it to 0 if you need an immediate redirect.
<head>
/* Source: hhttp://www.apphp.com/index.php?snippet=html-meta-tag-refresh */
<meta http-equiv="refresh" content="5;url=http://yourdomain.com/" />
</head>
@apphp-snippets
apphp-snippets / gist:4013547
Created November 4, 2012 20:23
This definition allows redirection to the provided URL in 5 seconds. You may set it to 0 if you need an immediate redirect.
<head>
/* Source: http://www.apphp.com/index.php?snippet=html-meta-tag-refresh#null */
<meta http-equiv="refresh" content="5;url=http://yourdomain.com/" />
</head>
@apphp-snippets
apphp-snippets / gist:4013533
Created November 4, 2012 20:21
Today with CSS3, you no longer need a background image for gradients. You can use CSS to add a gradient to the background of some elements on your page. For ex.: change the color hex values ("84c8d7" and "327fbd") to the gradient color you need.
<style>
/* Source: http://www.apphp.com/index.php?snippet=css-background-gradient */
.grad{
background: -webkit-gradient(linear, left top, left bottom, from(#84c8d7), to(#327fbd));
background: -moz-linear-gradient(top, #84c8d7, #327fbd);
filter:
progid:DXImageTransform.Microsoft.gradient(startColorstr="#84c8d7", endColorstr="#327fbd");
}
</style>
@apphp-snippets
apphp-snippets / gist:4013527
Created November 4, 2012 20:21
This can be used in casting shadows off block-level elements like divs, tables etc. (still not supported in IE7 and IE8). Parameters (from left to right): horizontal offset of the shadow, vertical offset of the shadow, blur radius (optional), spread radiu
<style type="text/css">
/* Source: http://www.apphp.com/index.php?snippet=css-box-shadow */
.shadow {
-moz-box-shadow: 4px 5px 5px 1px #777;
-webkit-box-shadow: 4px 5px 5px 1px #777;
box-shadow: 4px 5px 5px 1px #777;
}
.shadowIE {
background-color:#f5f5f5; /* need for IE*/