How to show email or mobile in secure way via php?


How to show email or mobile in secure way via php?



Suppose :-
I fetch the data from database of user there I fetch email or mobile number.


$mob = mobile;
$email = email;



I want it look like this :


Email = ab*******@g***.Com
Mobile = 12****8***



I I make this?





Please add additional specification to the problem you are facing. Do you want the email and mobile number to be shown like that on the front end, do you want them to be shown like that on the back end or do you want to store them like that in the database ?
– Dvorog
Jun 30 at 12:15





Only front end I want show like secure.
– Albert
Jun 30 at 13:09




1 Answer
1



Try this simple functions


function obfuscate_email($email, $secure_param) {
list($name, $domain) = explode("@", $email);
$name = substr($name, 0, $secure_param) . str_repeat("*", strlen($name) - $secure_param);
$domain = explode(".", $domain);
$domain[0] = substr($domain[0], 0, $secure_param) . str_repeat("*", strlen($domain[0]) - $secure_param);
$domain = implode(".", $domain);
return implode("@", [$name, $domain]);
}

function obfuscate_phone_number($phone_number, $secure_param) {
return substr($phone_number, 0, $secure_param) . str_repeat("*", strlen($phone_number) - $secure_param);
}

$email = "example@domain.com";
$phone_number = "500600700";

echo obfuscate_email($email, 3) . PHP_EOL;
echo obfuscate_phone_number($phone_number, 5) . PHP_EOL;



Result


exa****@dom***.com
50060****





In mobile what we do when we need like this : 12****6***. obfuscate_phone_number($phone_number, 2) . obfuscate_phone_number($phone_number, 1) .PHP_EOL; is this correct?
– Albert
Jun 30 at 11:45



obfuscate_phone_number($phone_number, 2) . obfuscate_phone_number($phone_number, 1) .PHP_EOL;





Pls reply, say something
– Albert
Jun 30 at 14:24





@Albert divide $phone_number into two strings (using substr) and use function like you say: obfuscate_phone_number($phone_number_first, 2) . obfuscate_phone_number($phone_number_last, 1)
– ventaquil
Jun 30 at 15:11


$phone_number


substr


obfuscate_phone_number($phone_number_first, 2) . obfuscate_phone_number($phone_number_last, 1)





Thank u! Boss..
– Albert
Jun 30 at 15:40





I am run it yet but..
– Albert
Jun 30 at 16:00






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Render GeoTiff to on browser with leaflet

How to get chrome logged in user's email id through website

using states in a react-navigation without redux