eire web design home page contact eire-web design eire web design and development site map
stepping on in business
• Welcome to Eire Web Design Ireland

Archive for October, 2007

Fighting Spam – Protect your forms

Thursday, October 18th, 2007

Everyone knows what Spam is. We all get unsolicited emails every day, and dealing with spam has never been a bigger battle.
Having a website that has any type of form means you are after opening a gate for spam.
Trying to close that gate and keep it close, for some people is a full-time job.
Below are some solutions that I found helpful:

1. Set a variable that will hold a number let’s say 6.
Set-up a session on form submission and increase the count by one anytime the form gets submitted by the same user, then check to see if it’s not equal or bigger then the variable you have set. If it is, display a message or redirect.
This is useful on contact forms.

2. On any other type of forms, like search, make sure you check the value of the submitted fields not to contain an email address
this can be easily done. 
e.g using php:

if(eregi( "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_GET["field_name"])){
   echo "You are not going to find an email address in the products table. Get real.";
   die();
}

3. Limit the amount of data a user can type into the form field by using the input attribute maxlength=”50″. 
You’ll be surprised how much you can type into an input field that has no “maxlenght” applied.
e.g.If you have a qty. field for a product to be added to the shopping cart you can limit the amount of data to 3 – maxlenght=”3″. 
Who would buy more then 999 products at a time?

4. Few months ago I was getting a lot of registrations on one of my website. Looking at all those new customers I noticed a similarity.
The first name and last name plus some other fields were exactly the same values, so i created a function that is checking the form for duplicate values:

if($x_first_name == $x_last_name){ 
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# here I add the ip address to the ban table,
then email all the form values to myself,
just in case there was a mistake
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
}

It worked for me very well. Managed to collect few IP’s in the database and until now none were for real.

5. Never trust Javascript (client-side) for form checking. Always do more checking using server-side (PHP, ASP, …)

6. Always check the values submitted to contain exactly what you are expecting.
e.g. If you are looking for numbers, then make sure you only get numbers. 

7. Use Captcha Security to prevent automated submissions.
    A good example here: Captcha Security

:::::::::: more will be added on as I find them ::::::::::::

PHP Friendly SQL Error message

Thursday, October 18th, 2007

No matter how much you try there will always be the day when you make a mistake in your sql accessing the database.
Sometimes queries are based on some sort of session which, if it times-out the next query to the database will show an error instead of getting the result expected. Sometimes the query comes from an old page in the Search Engines, the possibilities are unlimited.
Showing a Sql error to the visitor, could mean a lost customer, giving out too much details that are not meant to be seen, etc…

The biggest problem is “How do you know you have made a mistake?

The solution is to send yourself an email when that happens and instead of the error message displayed on the page, you can write a nice message to the visitor that he will accept quicker then “The page can not be displayed“. 
Not many visitors knows how to go back to your Home Page if there are no links that will redirect them there.

There is a simple example bellow that will do just that.

function ewd_db_connect($HOST,$USER,$PASS,$DB) {
 $conn = @mysql_connect($HOST, $USER, $PASS) or die(ewd_error($sSql="No Connection to the database"));
 @mysql_select_db($DB) or die(ewd_error($sSql="No Connection to the database"));
 return $conn;
}  

function ewd_db_close($conn){
 mysql_close($conn);
}
function ewd_query($strsql,$conn) {
 $rs = mysql_query($strsql,$conn);
return $rs;
}
function ewd_num_rows($rs) {
 return @mysql_num_rows($rs);
}
function ewd_fetch_array($rs) {
 return mysql_fetch_array($rs);
} function ewd_free_result($rs) {
 @mysql_free_result($rs);
}
function ewd_data_seek($rs,$cnt) {
 @mysql_data_seek($rs, $cnt);
}     

#this is where the fun begins
#if we get a sql error, will show a friendly message then email the error to the webmaster or yourself 

function ewd_error($sSql) {
 echo "We have encounter a problem accessing the database. An email has been send to the Administrator.\n
 We hope to bring the website back on line very soon.\n
 To go back to the home page Click Here (link to your home page)";
 #send email
 $to = "your_email_address";
 $subject = "Error on Website name";
 $headers = "Content-type: text/plain\r\n";
 $body = "Connection Error:". mysql_error();
 $body.="\n\n\nSql Error: ".$sSql;
 $body.="\n\n\nPage: ".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
 $body.="\n\n\nReferer".$_SERVER['HTTP_REFERER']."\n\nIP Address: " .$_SERVER['REMOTE_ADDR'];
 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
   ini_set("SMTP","localhost");
   ini_set("smtp_port","25");
 }
  #send email
  mail($to, $subject, $body, $headers);
}
//define your connection settings 

define("HOST", "localhost"); //domain
define("USER", "user_name"); //user name
define("PASS", "password"); //password
define("DB", "database_name"); //database name  

// Open connection to the database
$conn = ewd_db_connect(HOST, USER, PASS,DB);

Example how to use it:


$sSql= " Select , Update, Insert statement here ";
$rs = ewd_query($sSql,$conn) or die(ewd_error($sSql)); //this is where the magic happens
if (ewd_num_rows($rs) > 0){
  while($row = ewd_fetch_array($rs)){//do the loop
    //...display data
    //....................................................................................
    //....................................................................................
  } //end while
} //end if
ewd_free_result($rs); // free rs
ewd_db_close($conn);//close connection

Don’t get framed

Monday, October 15th, 2007

Recently I came across a website that  was displaying one of my pages in their own frame set which made it difficult to store the shopping cart session and was breaking the website functionality as well.

The solution was a small piece of Javascript added between the HEAD tags to remove all frames:


This script checks to see if the current page is the “top” page. If it is not, it tells the web browser to load the current web page as the top, thus wiping out any frames. Of course, this script won’t work with browsers that don’t understand scripting, or where scripting is turned off, but the script will work on most browsers, and that makes it a pretty effective deterrent

Tracking your Google AdWords for Click Fraud

Monday, October 15th, 2007

Recently I started a new AdWords campaign, and because the bids where hight on certain keywords / phrase, I have made an adwords tracking system for the campaign. 
Just wanted to know what the hack is going on, especially when 1 click could cost you as much as 5.00euro  or more for a decent position (6-9).

Not even 12 hours later, had a look at the log file and here is what I found:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ad id | ad name | no_kw_name | referer Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)  | ip-78.16.2.*** | 2007-05-30 22:30:35
ad id | ad name | no_kw_name | referer Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0) | ip-78.16.2.*** | 2007-05-30 22:32:48
ad id | ad name | no_kw_name | referer Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0) | ip-78.16.2.*** | 2007-05-30 22:33:30
ad id | ad name | no_kw_name | referer Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0) | ip-78.16.2.*** | 2007-05-30 22:35:19
ad id | ad name | no_kw_name | referer Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0) | ip-78.16.2.*** | 2007-05-30 22:50:28
ad id | ad name | no_kw_name | referer Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0) | ip-78.16.2.*** | 2007-05-30 23:15:12
ad id | ad name | no_kw_name | referer Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0) | ip-78.16.2.*** | 2007-05-30 23:15:26
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

I have taken few things out like referer, etc. and change the ip address but look at the time?

Some people really take competition to heart. Makes you laugh how low some could go.
Google detected click fraud on 4 of them and only charge me for 3 clicks, but still, how fair is that? 

I know there are programs out there that will track your ads, but some of the info they give might mean nothing to you at all, so i made this small package available for download.

Can be downloaded from here (Get AdWords Tracking Pack) for Free and please let us know how you get on with it.

What is Google AdWords?

Monday, October 15th, 2007

Google AdWords is a PPC (Pay Per Clickadvertising program started by Google Search Engine a few years back.

Is a quick way of getting visitors to your website, especially new websites that want to draw visitors or for launching new product/s, etc.
The ads appear at the top and right hand side of the Google Search page, as Sponsored Links on keywords / key phrases that you choose as per image below.

Google AdWords

You can get visitors to your website for as low as 0.03 Euro per click. 
It is Free to advertise and you only pay when your ad has been clicked, so if the impressions of your AdWords ad is 500 and you only got 5 clicks at 0.03 Euro the total own to Google is 0.15 Euro.
 
Hey, that’s a small price to pay for on-line advertising if that click could turn into a new customer, but it also has its drawbacks.

The secret of running a proper AdWords campaign lies in your chosen keywords and phrases, the copy of your ad, landing page, and much more.

Choosing the wrong keywords or phrases could get you clicks but not customers and then you wonder why?
One reason is that the landing page is not properly  formated or it has no relation between the keyword that your visitors used in his/her search.Also not having the right ad copy or keywords / phrases could get a lot of impressions but no clicks, and if the CTR (clickthrough rate) goes below 0.05% Google could disable your AdWords campaign.

The biggest mistakes that people make in their Google AdWords campaigns are very common and a very large percentage can be easily improved if they pay attention and put some effort into it. 

Take your time and analise every keyword / phrase that you are going to choose for your campaign, create the right Ad copy and you can save yourself hundreds or even thousands, or even better hire a professional to look after your campaign.

Good luck with your AdWords campaign.

Links...

Chicklets...
  • http://www.eire-webdesign.ie/blog/feed/
    http://www.eire-webdesign.ie/blog/feed/
    Google Reader or Homepage
    Add to My Yahoo!
    Subscribe with Bloglines
    Subscribe in NewsGator Online
    add to msn
    Add to My AOL
    Add to Technorati Favorites!
    pageflakes
    windows live