i am working on a project, it need email validation when user enter his email address check for availiblity. i wrote the php code in javascript it works fine but my problem is when some one see my page source it is displaying all user email address in javascript code. i want hide this one.
i wrote javascript code in seperate file but validation is not working.
if any one give idea, how hide javascript code in php, guide me please.
thanks
Any JavaScript can be read by anyone. It's a client side language.
This check will have to be done on the server; you can do it either during form submission, or use AJAX (maybe when the e-mail field looses focus (blur).)
You should check the availability of addresses through ajax. For example, see this tutorial on username availability checking explains how to do it for usernames; it should not be too difficult to change it for email addresses. What happens in this case is that:
This way, the browser never knows the full list of addresses, so no one can harvest them.
By the way, don't rely solely on your JavaScript validation, but be sure to do an availability check in your final PHP registration code too! Malicious users will turn off their JavaScript and reregister over an existing username! The only way to prevent this is on the server (since only you control the server).
I know this is very old post but with php or asp you can do this. but it will still be available to advanced geeks. basically you need 3 files 1. functions.js file
function testfunc(){
alert("test to see if it works...");
}
2. null_functions.php
<?php
$datetime=base64_encode(date("YmdHis") * 1.35489);
$cache = getparam("cache");
if ($datetime == $cache) {
$js = file_get_contents("functions.js");
echo $js;
}
//****************************************************************************************************
// functions
//****************************************************************************************************
function getparam($name)
{
if (is_string($name))
{
if ((bool)get_magic_quotes_gpc())
{
set_magic_quotes_runtime(0);
$param = isset($_POST[$name]) ? stripslashes($_POST[$name]) : false;
$param = isset($_GET[$name]) ? stripslashes($_GET[$name]) : $param;
}
else
{
$param = isset($_POST[$name]) ? $_POST[$name] : false;
$param = isset($_GET[$name]) ? $_GET[$name] : $param;
}
return $param;
}
else
{
return $name;
}
}
?>
3. index.php
<!DOCTYPE html>
<html>
<head>
<?php
$cache = base64_encode(date("YmdHis") * 1.35489); // multiply by some random number this must be same as on null_functions.php page
?>
<script src="<?php echo "null_functions.php?cache=$cache";?>">
</script>
</head>
<body onload="javascript:testfunc()">
</body>
</html>