Skip to content

Instantly share code, notes, and snippets.

View gr8pathik's full-sized avatar

Pathik Gandhi gr8pathik

View GitHub Profile
@gr8pathik
gr8pathik / php_errors_email.php
Last active December 30, 2015 00:19
Email PHP errors instead of displaying it
<?php
// Our custom error handler
function pg_error_handler($number, $message, $file, $line, $vars){
$email = "
<p>An error ($number) occurred on line
<strong>$line</strong> and in the <strong>file: $file.</strong>
<p> $message </p>";
$email .= "<pre>" . print_r($vars, 1) . "</pre>";
@gr8pathik
gr8pathik / gzcompress.php
Last active December 30, 2015 00:19
Compress data using gzcompress() - When working with strings, it is not rare that some are very long. Using the gzcompress() function, strings can be compressed. To uncompressed it, simply call the gzuncompress() function as demonstrated below:
<?php
$string =
"Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Nunc ut elit id mi ultricies
adipiscing. Nulla facilisi. Praesent pulvinar,
sapien vel feugiat vestibulum, nulla dui pretium orci,
non ultricies elit lacus quis ante. Lorem ipsum dolor
sit amet, consectetur adipiscing elit. Aliquam
pretium ullamcorper urna quis iaculis. Etiam ac massa
sed turpis tempor luctus. Curabitur sed nibh eu elit
@gr8pathik
gr8pathik / code.php
Last active December 30, 2015 00:19
Check if server is HTTPS
<?php
if ($_SERVER['HTTPS'] != "on") {
echo "This is not HTTPS";
}else{
echo "This is HTTPS";
}
@gr8pathik
gr8pathik / function.php
Last active December 30, 2015 00:19
PHP - Detect location by IP - Here is an useful code snippet to detect the location of a specific IP. The function below takes one IP as a parameter, and returns the location of the IP. If no location is found, UNKNOWN is returned. - Source: http://snipplr.com/view/48386/detect-location-by-ip-city-state/
<?php
function detect_city($ip) {
$default = 'UNKNOWN';
if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost')
$ip = '8.8.8.8';
$curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)';