Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Stoping bots submiting forms - Top Tips
Old 09-27-2007, 03:30 PM Stopping bots submiting forms - Top Tips
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
There are many ways to avoid having your website being attacked by bots. I'm going to go over them

CAPTCHA
Personally I'm not a big fan of CAPTCHA'' as it annoys users (having to type randoms letters which as difficult to read) and lots of spammers have made software to read the images.


Re-CAPTCHA
Similar to CAPTCHA, but this one you have 2 words. One is known to the computer, the other is from a book thats been scanned. If the word you known to the computer is correct, you allowed though. The scanned word makes the maker of Re-CAPTCHA a small amount of moneys (the computer can't read it...so you tell them the word).


Crouching CSS, Hidden Form
This technique involves having a field that is hidden (usually with CSS), and detecting if something has been put in it. If it has got content, A bot submitted the form.
The only problem with this one is, some bots can read CSS and know if a form is hidden. If CSS is disabled in the users browser they may also fill out the field.
Below is an example of code you use:
HTML Code:
<form id="form1" name="form1" method="post" action="">
  <label></label>
  <p>Field 1 -
    <input type="text" name="textfield" id="textfield" />
  </p>
  <p>
    <input type="text" name="textfield2" id="textfield2" style="visibility:hidden;" />
    <input type="submit" name="button" id="button" value="Submit" />
  </p>
  <p>&nbsp; </p>
</form>

Timestamp
This one is a little tricky, but can stop software submitting to you. What you need to do for this one, is generate a random number (say 999) and put it into a field and session. When the form has been submitted compare to see weather the timestamp posted matches the timestamp posted.
One of minor problems is, if the user has disabled session cookies, the session may not load. But you can overcome this with MySQL.
Below is some fancie PHP functions I have wrote:
PHP Code:
# TimeStamp Functions # Made By Rogem Networks (http://www.rogem.net) # Do Not remove Link back.
function createtimestamp(){
deletestamp();
$timestamp md5(rand(09999));
$timestamp md5($timestamp);
$timeset date("His").rand(09999).rand(09999).rand(09999);
$timeset $timeset;
$microtime microtime().rand(09999).rand(09999).rand(09999);
$microtime $microtime;
$timestampsession md5($timestamp);
$_SESSION["timestamp"."$timeset"."$microtime"] = $timestampsession;
$timestamp $timestamp."|||".$timeset."|||".$microtime;

// now give the person two options (html or timestamp standalone).
$return[0] = $timestamp;
$return[1] = '<input type="hidden" name="timestamp" value="'.$timestamp.'">';
return 
$return;
}

function 
checktimestamp(){
if(
$_POST['timestamp'] == TRUE){
$timestamp $_POST['timestamp'];
} else {
$timestamp $_GET['timestamp'];
}
$posted explode("|||",$timestamp);
if(
md5($posted['0']) == $_SESSION["timestamp".$posted['1'].$posted['2']]){
return 
"safe";
} else {
return 
"unsafe";
}
}

function 
deletestamp(){
$posted explode("|||",$_POST['timestamp']);
if(isset(
$_SESSION["timestamp".$posted['1']])){
unset(
$_SESSION["timestamp".$posted['1']]);
}


Scan whats sent
This is more of a 'if the above all pass' type thing, to detect if someone is physically submitting a form to you. For example:
PHP Code:
$subject "abcdef";
$pattern '/^porn/';
if(
preg_match($pattern$subject$matchesPREG_OFFSET_CAPTURE3)){
// Found spam
} else {
// Not found

__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 09-27-2007 at 04:24 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
 
Register now for full access!
Old 09-27-2007, 04:14 PM Re: Stoping bots submiting forms - Top Tips
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Common guys, It's a big post but a reply would be nice LOL

Also, Just noticed I can't deleted my own posts....
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 09-27-2007 at 04:23 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 09-27-2007, 04:40 PM Re: Stoping bots submiting forms - Top Tips
Skilled Talker

Posts: 59
Name: Dan
Trades: 0
Interesting post, I'm currently looking for a way to stop spambots from submitting forms without having to use a hideous CAPTCHA inksplat on my page.

I'm currently thinking about using a variation on the KittenAuth theme as the use of images offers some interesting branding benefits.

I hadn't considered the use of a hidden field, although as you point out it has a couple of potential drawbacks in that it can be beaten by clever bots and is prone to false positives if people fill them out.

In fact there are drawbacks with pretty much any solution, usually from an accessibility point of view.

**** spammers.

Aside from spammers does anyone have any problems with script-kiddie style hacking attempts on forms being submitted with common system files and sql commands in the fields?
Monkey Do is offline
Reply With Quote
View Public Profile
 
Old 09-28-2007, 01:15 PM Re: Stoping bots submiting forms - Top Tips
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
That kitten idea looks like a nice way forward, but to be honest I can't tell what is a kitten. I think a 'click the correctly spelled word' might work a tad better.

I find, base64'ing everything going into your database tends to stop sql injections. I'll write a post on it d:

With PHP injections, putting the information into an array and adding slashes tends to do the trick. Also when you echo them, put the variable into '{', it's some php trick.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Reply     « Reply to Stoping bots submiting forms - Top Tips
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13872 seconds with 12 queries