Monday, June 14, 2010

Easy Learning Updates - Feature for preventing Spam email and New Topics such as Football Players





As I mentioned in my previous post we are continuously improving our Easy Learning.

We are already having a feature for sending the score thro' emails. Some spammers started misusing this feature for sending some junk emails continuously. (Anyway they can not change the built-in content).

Initially I wanted to integrate the Easy Learning module with our Forum to avoid spammers. The phpBB forum is lot of options for blocking the user and ip to preventing the spammers.

But this integration will force everyone to become our forum members for playing this Easy learning.
I don't want to force easy learning users to become our Forum members.

So, I added custom php coding to avoid this issue.
I created new table and php function for logging the ip of the user when sending the email.
The new code won't allow the user if he tries to send email again within a hour.

I added below piece of code in the mail sending page.

log_ip();

$pagename=$_SERVER['PHP_SELF'];
if (is_spam($pagename)) //Don't send the email if email is already sent within a hour from the same ip address
{
echo "It seems you recently sent email. Please try after sometime";
echo '<a href="menu.php">Go Back</a>';
die;
}


And, added below functions in the function file.

function ip_address_to_number($IPaddress)
{

if ($IPaddress =="")
{
return 0;
}
else
{
$ips = explode('.', $IPaddress);
return ($ips[3] + $ips[2] * 256 + $ips[1] * 65536 + $ips[0] * 16777216);
}
}
function log_ip()
{
$ipaddress=$_SERVER["REMOTE_ADDR"];
$ipnum=ip_address_to_number($ipaddress); //for converting ipaddress in x.x.x.x format to numerical value
$referrer=$_SERVER['HTTP_REFERER'];
$page=$_SERVER['PHP_SELF'];
$sql="insert into ip_log(ipaddr,ipnum,referrer,logedtime,page) values('$ipaddress',$ipnum,'$referrer',NOW(),'$page')";
$query=mysql_query($sql);

}

function is_spam($page)
{
$is_spam=false;
$ipaddress=$_SERVER["REMOTE_ADDR"];
$ipnum=ip_address_to_number($ipaddress); //for converting ipaddress in x.x.x.x format to numerical value
$referrer=$_SERVER['HTTP_REFERER'];
$sql="select * from ip_log where page='$page' and ipnum=$ipnum and logedtime > (NOW() - INTERVAL 1 HOUR)";
$query=mysql_query($sql);
if (mysql_num_rows($query)>1) //If there are more than one entry within a hour
{
$is_spam=true;

}
return $is_spam;
}

And we added new topics such as Football players and Photo Shop Tools.




More Articles...
You can bookmark this blog for further reading, or you can subscribe to our blog feed.

No comments:

Search This Blog