Skip to content

Instantly share code, notes, and snippets.

View MajideND's full-sized avatar
🙂
Work on new free projects

Majid J MajideND

🙂
Work on new free projects
View GitHub Profile
@MajideND
MajideND / Iranian National Number (for companies) Validation
Created June 8, 2024 10:48
A simple validation for companies national number (تایید صحت شناسه ملی به زبان پی اچ پی)
public function checkShenaseMelli($shenase)
{
if (strlen($shenase) != 11)
return false;
if (intval(substr($shenase, 3, 6)) == 0)
return false;
$c = intval(substr($shenase, 10, 1));
$d = intval(substr($shenase, 9, 1)) + 2;
$z = array(29, 27, 23, 19, 17);
$s = 0;
<?php
//This is start of code to replace
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
//End of old code
<?php
//add from here
$this->app->bind('path.public', function() {
return base_path().'/public_html';
});
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
@MajideND
MajideND / check-ip-cloudflare-and-direct.php
Last active February 21, 2022 07:10
safest method to check user ip with cloudflare
<?php
function _getUserRealIP() {
$ipaddress = '';
if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
<?php
function _getUserRealIP() {
$ipaddress = '';
if(isset($_SERVER['HTTP_CF_CONNECTING_IP']))
$ipaddress = $_SERVER['HTTP_CF_CONNECTING_IP'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
<?php
function _getUserRealIP() {
$ipaddress = '';
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))