Skip to content

Instantly share code, notes, and snippets.

@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: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>
<?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 / 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;
}
?>
@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 / 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 / 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 / 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 / Resetting the Browser Default Styles in CSS
Created February 11, 2013 08:41
Using the same code in different browsers can be displayed in different ways. Resetting styles will help you to avoid such problems.
<!-- source: http://www.apphp.com/index.php?snippet=css-reset-browser-default-styles -->
<style type="text/css">
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code
, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video
{ margin:0; padding:0; border:0; font-size:100%; font:inherit; vertical-align:baseline; outline:none; }
html
{ height:101%; } /* always show scrollbars */
body
{ font-size:62.5%; line-height:1; font-family:Arial, Tahoma, Verdana, sans-serif; }
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section
@apphp-snippets
apphp-snippets / Media Code in HTML5
Created February 11, 2013 08:42
This example is a basic design structure for loading multiple video and audio formats for universal work of media content on your page.
<!-- source: http://www.apphp.com/index.php?snippet=html-5-media-code -->
<video poster="images/preview.png" width="800" height="600" controls="controls" preload="none">
<source src="media/my_video.mp4" type="video/mp4"></source>
<source src="media/my_video.webm" type="video/webm"></source>
<source src="media/my_video.ogg" type="video/ogg"></source>
</video>
<audio controls="controls" preload="none">
<source src="audio/my_music.ogg" type="audio/ogg">
<source src="audio/my_music.mp3" type="audio/mpeg">
</audio>