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 / php
Created April 11, 2021 07:09
Laravel Iranian mobile number Validation (ساخت validation شماره همراه در لاراول)
//use this code in your function:
use App\Verification;
use Symfony\Component\HttpFoundation\Response;
$messages = [
'number.required' => 'شماره تلفن الزامی است',
'number.unique' => 'شماره تکراری است لطفا وارد شوید.',
'number.regex' => 'فرمت شماره شما صحیح نیست',
@MajideND
MajideND / get-ip.php
Last active February 21, 2022 06:50
Safest code to get user real IP Address in PHP
<?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_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']))
<?php
function _getUserRealIP() {
$ipaddress = '';
if(isset($_SERVER['HTTP_CF_CONNECTING_IP']))
$ipaddress = $_SERVER['HTTP_CF_CONNECTING_IP'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
@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 -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
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;"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
<?php
//add from here
$this->app->bind('path.public', function() {
return base_path().'/public_html';
});
<?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