I used to get so much spam in my mailbox everyday that I was spending more time deleting it then I was adding new content, maintaining sites, or starting new sites combined (typical story right). Jag brukade få så mycket spam i min brevlåda varje dag att jag spenderade mer tid på att radera det sedan jag var att lägga till nytt innehåll, underhålla webbplatser, eller att starta nya webbplatser i kombination (typisk berättelse höger). Some of your website spam is not preventable, or, it is preventable, but at the cost of usability and/or good information getting caught in the “bad stuff” as well. En del av din webbplats spam är inte kunnat förhindras, eller är det förebyggas, men på bekostnad av användbarhet och / eller bra information att få fångas i den "dåliga grejer" också.

No doubt, if you’re serious about web development you’re going to be creating and interacting with forms on a regular basis. Ingen tvekan om, om du menar allvar med webbutveckling du kommer att vara att skapa och interagera med former på regelbunden basis. Especially with this new web 2.0 attitude every has…gee wiz, what’s that? Speciellt med denna nya web 2.0 attityd alla har ... hoppla Wiz, vad är det?

CAPTCHA CAPTCHA
CAPTCHA is the number one method most people are using to prevent spam today. CAPTCHA är antalet en metod som de flesta människor använder för att förhindra spam i dag. What is it? Vad är det?

“A CAPTCHA is a challenge response test used on computers to check if the user is human. "En CAPTCHA är en utmaning svar test som används på datorer för att kontrollera om användaren är mänskliga. A common kind of CAPTCHA that is used on websites requires that the visitor type the letters and numbers of a distorted image. En vanlig typ av CAPTCHA som används på webbplatser kräver att besökaren skriver in bokstäver och siffror av en snedvriden bild. This method is based on the fact that is difficult for computers to extract the text from the image while it is very easy for humans.” - captchacreator.com Denna metod bygger på att det är svårt för datorer för att extrahera text från bilden medan det är mycket lätt för människor. "- Captchacreator.com

Here’sa few resources to scripts so you’ll be able to implement that functionality into your own forms: Här är några resurser för att skript så kommer du att kunna genomföra denna funktionalitet till ditt eget sätt:

Escape Data - Prevent SQL Injections Escape Data - förhindra SQL-injektioner
Capcha is usless if you’re leaving your form unprotected from attack. Capcha är usless om du lämnar din form oskyddade mot attacker. Remember to filter post strings with addslashes() or mysql_real_escape_string() . Kom ihåg att filtrera efter strängar med addslashes () eller mysql_real_escape_string ().

Also take a look at these functions for other similar kind of checks that might be useful: Också ta en titt på dessa funktioner för liknande typ av kontroller som kan vara till nytta:

  • htmlspecialchars() - Escapes the following characters: &,’,”,>,< ...that is the ampersand, single quote, double quote, less than, and greater than symbols. htmlspecialchars () - undgår följande tecken: &,',",>,< ... det är tecken, enkla citattecken, dubbla citattecken, mindre än och större än symboler.
  • strip_tags() - Strips out all HTML and PHP code from the given string. strip_tags () - tar bort alla HTML-och PHP-kod från den angivna strängen.
  • htmlentities() - Converts ALL characters to their HTML entities equivalent (this is a more catch all version of htmlspecialchars). htmlentities () - konverteras alla tecken till HTML-enheter motsvarande (detta är en mer fånga alla version av htmlspecialchars).
  • urlencode() - Encodes the URL to pass strings on a GET method. urlencode () - kodar webbadressen passera strängar på en GET-metoden. As I mentioned, don’t use GET with forms. Som jag nämnde, inte använder GET med former. This is useful when you’re passing user input variables for other reasons. Detta är användbart när du passerar användare ingående variablerna av andra skäl.

Remember, once you convert data like this using one of the above functions, you can undo it for readability and output by using its reverse function. urlencode() for example has urldecode() to undo its actions so you can begin using the string as you would have before the encode. Kom ihåg att när du konverterar data så här med hjälp av någon av ovanstående funktioner kan du ångra det för läsbarhet och produktion genom att använda sin omvänd funktion. Urlencode () har till exempel urldecode () för att ångra sin verksamhet så att du kan börja använda den sträng som du skulle ha innan koda.

Check Request Method Kontrollera begäran metod
Throw an if statement around your existing form processor that checks to see if data is coming from the globals post variable. Kasta om ett uttalande kring din nuvarande form processor som kontroller för att se om informationen kommer från globals efter variabel. If not, then the user is not accessing your form the way you designed it to be used. Om inte, då användaren inte tillgång till din form på det sätt du konstruerade att använda det.

  1. <?php
  2. if ( $_SERVER [ ‘REQUEST_METHOD’ ] == ‘POST’ ) {
  3. //typical form processes
  4. } else {
  5. echo "The form can not be used like that" ;
  6. }
  7. ?>

Change this to GET if you’re using that instead. Ändra detta till GET om du använder den i stället. However, I would high recommend you never use that method as it is more insecure. Jag skulle dock hög rekommenderar att du aldrig använda denna metod eftersom det är mer osäkra.

Check Request Source Kontrollera begäran Källa
You should also check to see if the request is originating from your own server. Du bör också kontrollera att se om begäran från din egen server. This is a very common method of form abuse which doesn’t necessarily mean you’ll be receiving spam. Detta är en mycket vanlig metod i form missbruk vilket inte nödvändigtvis betyder att du fått spam. If you’re server is getting a lot of bounced emails to its default email you may have someone abusing your site in this manner. Om du servern blir en hel del studsade e-postmeddelanden till sin standardprogram för e-post kan du ha någon missbrukar din webbplats på detta sätt.

  1. <?php
  2. $source = $_SERVER [ ‘HTTP_HOST’ ] ;
  3. //or if you want to detect just the domain you can use a regular expression to filter it.
  4. $source = ereg_replace ( "^(www.)?([^.] ).[^.] $" , " \\ 2" , $_SERVER [ ‘HTTP_HOST’ ] ) ;
  5. if ( $source !== "robmalon.com" ) {
  6. echo "you are illegally accessing this script" ;
  7. } else {
  8. //typical form processes
  9. }
  10. //The referrer should also be from your own domain…Likewise, if there is no referral then the user obviously isnt using your form correctly (so we dont have to check for that).
  11. //Note: stristr() searches for the first occurrence of a string inside another string.
  12. if ( stristr ( getenv ( "HTTP_REFERER" ) , $source ) ) {
  13. //typical form processes
  14. } else {
  15. echo "you are illegally accessing this script" ;
  16. }
  17. ?>

Using Regular Expressions For Data Validation Använda vanliga uttryck för validering av uppgifter
I like to check data using preg_match (or any of the regular expression functions). Jag gillar att kontrollera uppgifter med hjälp av preg_match (eller någon av de vanliga uttrycket funktioner). This method kills a lot of birds with one stone. Denna metod dödar en massa flugor i en smäll. Why write separate functions to check if a string is empty, then another if it allows numbers, and another if it allows alpha characters, and another to specific field length, and another…you get the point. Varför skriva separata funktioner för att kontrollera om en sträng är tom, sedan en annan om den gör det möjligt för nummer, och en annan om den gör det möjligt för bokstäver, och en annan till specifika området längd, och en annan ... du får det.

if (!preg_match(”/^[A-z0-9]{5,15}$/”, $name)) $error .= “<li class=\”errors\”>The Name field can only contain letters and numbers (no spaces) and can only be up to 15 characters long.</li>”; if (! preg_match ("/^[ A-Z0-9] (5,15 }$/", $ namn)) $ error .= "<li class=\"errors\"> Fältet Namn kan bara innehålla bokstäver och nummer (utan mellanslag) och kan bara vara upp till 15 tecken långa. </ li> ";

In the preg_match I am checking that the name field only contains alphanumeric values (case insensitive) and needs to be at least 5 to 15 characters in length. I preg_match jag kontrollera att namnet endast innehåller alfanumeriska värden (bokstäver) och måste vara minst 5 till 15 tecken. If you don’t meet that specification appropriate text is added to $error. Om du inte uppfyller denna uppgift lämplig text läggas till $ fel.

Using “[variable] [dot][equals] [text]” in this fashion allows me to keep an ongoing variable that I’m adding to. Använda "[variabel] [dot] [lika] [text]" på detta sätt gör det möjligt för mig att hålla en kontinuerlig variabel som jag lägger till. I can then check to see if $error contains any data before my script does any significant queries. Jag kan då kontrollera om $ fel innehåller alla data innan mitt manus innebär någon betydande frågor. If there are errors you can spit them out by echoing $error and ask the user to correct them. Om det är fel att du kan spotta ut dem med att upprepa $ fel och ber användaren att rätta till dem. I then use CSS to style my errors which you can see with class=\”errors\”. Jag sedan använda CSS till stil mitt fel som du kan se med class = \ "fel \".

Regular expressions defiantly have a learning curve on them but they are one of the best tools that can help simplify your life in a variety of situations. Reguljära uttryck trots har en inlärningskurva på dem men de är en av de bästa verktyg som kan bidra till att förenkla ditt liv i olika situationer. I’ll go into more detail about them down the road but for now you may want to buy a book or do some Googling. Jag kommer att närmare gå in på dem på vägen men nu kan du köpa en bok eller göra vissa googla.

The Non-Technical Recap Den icke-tekniska återblick
-Implement a CAPTCHA script. -Genomföra en CAPTCHA skript.
-Escape slashes (and other bad characters). -Escape snedstreck (och andra dåliga tecken).
-Check to see if data is coming to your form using the correct method. -Kontrollera om uppgifterna kommer till din form använder rätt metod.
-Check to see if the request is originating from your own server. -Vill du kolla om en begäran från din egen server.
-Check data using a regular expression. -Kontrollera data med hjälp av ett vanligt uttryck.

This is just the tip of the iceberg for what I can tell you about spam. Det här är bara toppen på isberget för vad jag kan säga om skräppost. Thats why I’ve decided to make a mini series of it. Det var därför jag har bestämt att göra en mini-serie av det. Over the next couple weeks I will be bringing you more detailed ways I deal with spam. Under de närmaste par veckor kommer jag att föra dig närmare hur jag handskas med skräppost. Comment below or email me about your own spam preventative methods. Kommentera nedan eller maila mig om ditt egna skräpposten förebyggande metoder. If it is a new or unique technique I will post it in a future blog along with a link back to your blog. Om det är en ny eller unik teknik jag kommer att publicera det i en framtida blogg tillsammans med en länk till din blogg. Just write in the comments below and include your URL in the website field. Bara skriva i kommentarerna nedan och inkludera webbadressen i webbplatsen området.


1 Comment(s) On 1 Kommentar (er) Den

"5 Ways To Catch And Prevent Website Form Spam - Part 1" "5 sätt att fånga och förhindra Webbsida Formulär Spam - Del 1"
  1. MyAvatars 0.2 Rob - Mar 5, 2008 Rob - 5 mars, 2008

    It just occured to me…setting up those if statements with a die() statement might be easier for a quick and dirty method. Det bara slog mig ... att upprätta dessa om uttalanden med en dö () kan vara lättare för en snabb och smutsig metod. Which I’m sure most of you at least for now would want a quickfix to just toss in. Keep that in mind…Something like this: Som jag är säker på att de flesta av er åtminstone för nu vill ha en quickfix att bara slänga in tänka på ... Ungefär så här:

    if ($_SERVER[‘REQUEST_METHOD’] !== ‘POST’) { die(”The form can not be used like that”); } if ($ _SERVER [ 'REQUEST_METHOD']! == "POST") (die ( "form inte kan användas på det viset");)

    You can put that anywhere at the beginning of a script for it to take effect without worrying about existing code too much. Du kan placera den var som helst i början av ett skript för att den skall träda i kraft utan att behöva oroa dig för befintlig kod för mycket.



Leave A Comment: Lämna en kommentar:

Comments RSS Feed Kommentarer RSS-flöde

5 Plus 1 = 5 Plus 1 =

Custom Theme by Rob Malon | Content & Design © 2008 - Rob Malon [dot] Com. Anpassad Tema av Rob Malon | Content & Design © 2008 - Rob Malon [dot] Com. "));
"));