Skip to content

Instantly share code, notes, and snippets.

View vhdm's full-sized avatar
🎯
Focusing

Vahid vhdm

🎯
Focusing
View GitHub Profile
@vhdm
vhdm / get_ip_address.php
Last active September 6, 2015 15:19
Get ip address in php
<?php
function get_ip_address()
{
if (isset($_SERVER)) {
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) && ip2long($_SERVER["HTTP_X_FORWARDED_FOR"]) !== false) {
$ipadres = $_SERVER["HTTP_X_FORWARDED_FOR"];
} elseif (isset($_SERVER["HTTP_CLIENT_IP"]) && ip2long($_SERVER["HTTP_CLIENT_IP"]) !== false) {
$ipadres = $_SERVER["HTTP_CLIENT_IP"];
} else {
$ipadres = $_SERVER["REMOTE_ADDR"];
@vhdm
vhdm / fagd.php
Last active September 6, 2015 15:23
Convert string to image in php (just support Persian numbers and Chars)
<?php
#Updated by Vahid Mahmoudian
#http://vhdm.ir
#http://persiangd.berlios.de
#Copyright (C) 2007 Milad Rastian (miladmovie[_at_]gmail)
#thanks to Bagram Siadat (info[_at_]gnudownload[_dot_]org) (bug fix and new developer)
#tahanks to Ramin Farmani (bug fix)
#
#This program is free software; you can redistribute it and/or
@vhdm
vhdm / google2fa.php
Last active June 5, 2024 08:11
Google TOTP Two-factor Authentication for PHP
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@vhdm
vhdm / date_and_time.txt
Created September 6, 2015 20:43
PHP provides over thirty-five case-sensitive characters that are used to format the date and time. These characters are
Day j Day of the Month, No Leading Zeros 1 - 31
Day d Day of the Month, 2 Digits, Leading Zeros 01 - 31
Day D Day of the Week, First 3 Letters Mon - Sun
Day l (lowercase 'L') Day of the Week Sunday - Saturday
Day N Numeric Day of the Week 1 (Monday) - 7 (Sunday)
Day w Numeric Day of the Week 0 (Sunday) - 6 (Saturday)
Day S English Suffix For Day of the Month st, nd, rd or th
Day z Day of the Year 0 - 365
Week W Numeric Week of the Year (Weeks Start on Mon.) 1 - 52
Month M Textual Representation of a Month, Three Letters Jan - Dec
@vhdm
vhdm / _pcalendar.php
Last active September 6, 2015 21:35
Persian calendar
<?php
require_once("pcalendar.php");
$datex = new jDateTime(true, true, 'Asia/Tehran');
echo $datex->date('Y-m-d',time());
?>
@vhdm
vhdm / country_from_ip.php
Last active September 6, 2015 21:34
Get country from ip
<?
// Let me start off by saying I do not take full credit for this!
// I needed a way to get my traffic's country for Adverts...
// for some reason, json_decode wasn't working, so this is an alternative.
// json_decoder function from PHP.net
// file_get_contents_curl basic data retrieval function
// how to use:
// include('country.php');
// $userCountry=getTheCountry();
// output is 2 character country code, US, CA, etc...
@vhdm
vhdm / random_string.php
Last active September 6, 2015 21:33
Generate random string
<?php
function random_string($len=20){
$randstr = '';
srand((double)microtime()*1000000);
for($i=0;$i<$len;$i++){
$n = rand(48,120);
while (($n >= 58 && $n <= 64) || ($n >= 91 && $n <= 96)){
$n = rand(48,120);
}
$randstr .= chr($n);
@vhdm
vhdm / human_size.php
Created September 6, 2015 21:25
Human readable file size
<?php
function human_size ($size) {
if ($size <= 1024) return $size.' Bytes';
else if ($size <= (1024*1024)) return sprintf('%d KB',(int)($size/1024));
else if ($size <= (1024*1024*1024)) return sprintf('%.2f MB',($size/(1024*1024)));
else return sprintf('%.2f Gb',($size/(1024*1024*1024)));
}
echo human_size(32768);
?>
@vhdm
vhdm / hex_to_rgb_to_hex.php
Created September 6, 2015 21:29
Hex To RGB and RGB To Hex
<?php
error_reporting(0);
function toHex($N) {
if ($N==NULL) return "00";
if ($N==0) return "00";
$N=max(0,$N);
$N=min($N,255);
$N=round($N);
$string = "0123456789ABCDEF";
$val = (($N-$N%16)/16);
@vhdm
vhdm / last_inserted_id.php
Created September 6, 2015 21:32
Get last inserted id
<?php
// Insert into database
mysql_query("INSERT INTO my_table (`column1`, `column2`) VALUES ('one', 'two')");
// Next Get what the auto incremented number was that was inserted
$id = mysql_insert_id();
// Display it...
echo $id;
?>