Skip to content

Instantly share code, notes, and snippets.

@apphp-snippets
apphp-snippets / jQuery Loading Fallback
Created August 12, 2013 08:33
Nowadays majority of sites uses the jQuery JavaScript library. A lot of them also make use of Google's hosted version of the library from some reasons: faster loading, better cross site caching etc. However, what if there is ever a problem and jQuery is not loaded from Google? For example when you work on localhost and there is no Internet conne…
<!-- http://www.apphp.com/index.php?page=html_snippets -->
<!-- Grab Google CDN's jQuery and load local version if necessary -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">!window.jQuery && document.write('<script src="js/jquery-1.4.2.min.js"><\/script>')</script>
@apphp-snippets
apphp-snippets / Center Website Content with CSS
Created August 12, 2013 08:31
Today in the days of high-resolution widescreen displays, it's annoying to visit websites that are formatted like it's 1990's. aligned all the way to the left. Make sure your website doesn't suffer the same fate by forcing it;s content to center horizontally and vertically.
<style type="text/css">
/* source: http://www.apphp.com/index.php?snippet=css-center-site-content */
/* Center your website horizontally */
.wrapper{
width:960px;
display:table;
margin:auto;
}
/* Center certain content vertically */
@apphp-snippets
apphp-snippets / Get Remote IP Address in PHP
Created May 19, 2012 19:10
This code allows to get the IP address from which the user is viewing the current page.
<?php
/* Source: http://www.apphp.com/index.php?snippet=php-get-remote-ip-address */
function getRemoteIPAddress(){
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
return $ip;
}
/* If your visitor comes from proxy server you have use another function
to get a real IP address: */