Skip to content

Instantly share code, notes, and snippets.

View gr8pathik's full-sized avatar

Pathik Gandhi gr8pathik

View GitHub Profile
@gr8pathik
gr8pathik / getRealIpAddress.php
Created December 3, 2013 07:28
Get Real IP Address in PHP
<?php
function getRealIPAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
@gr8pathik
gr8pathik / directory_listing.php
Created December 3, 2013 07:30
Directory Listing in PHP
<?php
function list_files($dir)
{
if(is_dir($dir))
{
if($handle = opendir($dir))
{
while(($file = readdir($handle)) !== false)
{
<?php
function resize($img, $w, $h, $newfilename) {
//Check if GD extension is loaded
if (!extension_loaded('gd') && !extension_loaded('gd2')) {
trigger_error("GD is not loaded", E_USER_WARNING);
return false;
}
//Get Image size info
@gr8pathik
gr8pathik / flattenArray.js
Created July 18, 2017 12:25
Flatten Array - Javascript
function flattenArray(array) {
var arrayPool = [];
if(array.length > 0) {
for(var i=0; i < array.length; i++){
if(array[i].constructor === Array){
arrayPool = arrayPool.concat(flattenArray(array[i]));
} else {
arrayPool.push(array[i]);
}
}