Last active
February 14, 2019 09:43
-
-
Save kdes70/1a09328df6b2873a72e3c85fd766cf9e to your computer and use it in GitHub Desktop.
Helpers functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Simple way of masking emails | |
function mask_email($email ) { | |
$char_shown = 2; | |
$mail_parts = explode("@", $email); | |
$username = $mail_parts[0]; | |
$len = strlen( $username ); | |
if( $len <= $char_shown ){ | |
return implode("@", $mail_parts ); | |
} | |
//Logic: show asterisk in middle, but also show the last character before @ | |
$mail_parts[0] = substr( $username, 0 , $char_shown ) | |
. str_repeat("*", $len - $char_shown - 1 ) | |
. substr( $username, $len - $char_shown + 1 , 1 ) | |
; | |
return implode("@", $mail_parts ); | |
} | |
function getRealUserIp() | |
{ | |
switch(true){ | |
case (!empty($_SERVER['HTTP_X_REAL_IP'])) : return $_SERVER['HTTP_X_REAL_IP']; | |
case (!empty($_SERVER['HTTP_CLIENT_IP'])) : return $_SERVER['HTTP_CLIENT_IP']; | |
case (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) : return $_SERVER['HTTP_X_FORWARDED_FOR']; | |
default : return $_SERVER['REMOTE_ADDR']; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment