CAPTCHA is actually an acronym for “Completely Automated Public Turing test to tell Computers and Humans Apart”. As the name implies, it is a computer-generated test which aims to separate a bot (automated program) from a live, breathing human being online. The “Turing” refers to Alan Turing, a computer scientist who, in the 1950s, undertook research to distinguish a man from a machine.
source: http://www.tech-faq.com/captcha.shtml
Archive for the ‘developer’s Guide’ Category
what is captcha
Tuesday, June 2nd, 2009 by dreamluverzarray_diff_key
Tuesday, June 2nd, 2009 by dreamluverz(PHP 5 >= 5.1.0RC1)
array_diff_key – Computes the difference of arrays using keys for comparison
Description
array array_diff_key ( array array1, array array2 [, array ...] )
array_diff_key() returns an array containing all the values of array1 that have keys that are not present in any of the other arguments. Note that the associativity is preserved. This function is like array_diff() except the comparison is done on the keys instead of the values.
The two keys from the key => value pairs are considered equal only if (string) $key1 === (string) $key2 . In other words a strict type check is executed so the string representation must be the same.
Note: Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using array_diff_key($array1[0], $array2[0]);.
source: http://ph.php.net/array_diff
domain pointing to a folder
Tuesday, June 2nd, 2009 by dreamluverzThis approach has you code the first part of the domain or subdomain name and the associated subdirectory in your .htaccess file. Â For example:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/subdirectory/
RewriteCond %{HTTP_HOST} ^(www\.)?name\.
RewriteRule ^(.*)$ subdirectory/$1 [L]
Note the second line has name, NOT name.com. Â And note that there are some restrictions when using this method.
- Domains and subdomains are treated exactly the same. The pointing is based on the first argument of the url. In this example name.com (as a pointed domain name) or name.domain.com (as a pointed subdomain) ends up at htdocs/subdirectory.  This is particularly useful in certain situations, for example if you want the subdomains of more than one domain to point to the same place, or if you have both a .com and a .net domain name you want pointed to the same place.
- You must create a subdirectory under htdocs for every domain and subdomain you wish to be pointed. The subdirectory name is then coded into the htaccess file.
- The first argument in the url must be unique. You cannot have two domains or subdomains with the same name. sub.domain1.com and sub.domain2.com will both go to the same subdirectory.
- It defaults to allow www. as a prefix on any domain or subdomain.
- The root directory with this htaccess file is the “drop through” for any domain or subdomain not found. You may want to put an error not found page as the default page. Or, you could choose to have your main website be the “drop through” and just leave that one in the root.
There is also a simplified variation of this method that can be used in less complex situations where you are simply pointing a domain name and want ALL subdomains of that one domain to be pointed to a specific directory. Â In this example name.com and any subdomain (including www) of that domain would be pointed to htdocs/subdirectory:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/subdirectory/
RewriteCond %{HTTP_HOST} name.com$
RewriteRule ^(.*)$ subdirectory/$1 [L]
In both examples, the htacess code works this way. Â The first two lines set up the Apache server rewrite process. Â Then you have two RewriteCond statements and a RewriteRule for EACH domain or subdomain you wish to point.
source: http://tips-scripts.com/pointing
fading image using javascript
Tuesday, June 2nd, 2009 by dreamluverzShow me what it does!
Click on a link above to make the image disappear and re-appear by gradually fading in/out. It uses CSS transparency, in CSS you can set the transparency in different ways. To ensure that it works on most browsers we use all three.
- opacity: 0.5;
This one is the official CSS3 method, at the moment it works in newer Mozilla (Gecko) browers, Safari and Opera. - -moz-opacity: 0.5;
This one works in older versions of Mozilla browsers. - -khtml-opacity: 0.5;
This is used by older versions of browsers that use the KHTML and WebKit rendering engine, namely Konquerer on Linux and Safari on Mac OS X. - filter: alpha(opacity=50);
This one works only in MSIE.
MSIE warning
This trick however doesn’t work with MSIE all the time. For example, it won’t work unless it has a specified width and/or height. Yes, that’s weird. MSIE sucks. Normal browsers like Mozilla will do it right.
![]() This <div> has a can be made transparent in MSIE, it has a specified width of 300px. |
![]() This <div> has no specified width, transparency doesn’t work in MSIE. |
Mozilla warning
No browser is perfect, Mozilla (latest version at the time of writing is 1.6) has a few bugs too.
JavaScript fun
OK, here is the real work being done. This JavaScript has two separate functions. The first one, opacity() is called first, it sets the timer and speed.
Then the if() looks whether opacStart is larger then opacEnd, if so, the Opacity will go backwards, else, it will go forward.
setTimeOut() will cause a short delay before calling changeOpac() so that we can actually see the fading effect.
The function changeOpac() does nothing more than setting the 3 different opacity styles for the appropriate element. Notice that you can’t use dashes (-) in style names in JavaScript, instead you must use a CAPITAL letter. In this example you can see changing -moz-opacity changing into MozOpacity, the same thing applies to all styles that contain dashes.
function opacity(id, opacStart, opacEnd, millisec) {
//speed for each frame
var speed = Math.round(millisec / 100);
var timer = 0;
//determine the direction for the blending, if start and end are the same nothing happens
if(opacStart > opacEnd) {
for(i = opacStart; i >= opacEnd; i–) {
setTimeout(“changeOpac(” + i + “,’” + id + “‘)”,(timer * speed));
timer++;
}
} else if(opacStart < opacEnd) {
for(i = opacStart; i <= opacEnd; i++)
{
setTimeout(“changeOpac(” + i + “,’” + id + “‘)”,(timer * speed));
timer++;
}
}
}
//change the opacity for different browsers
function changeOpac(opacity, id) {
var object = document.getElementById(id).style;
object.opacity = (opacity / 100);
object.MozOpacity = (opacity / 100);
object.KhtmlOpacity = (opacity / 100);
object.filter = “alpha(opacity=” + opacity + “)”;
}
Fade in/out with only one link
There is more that can be done! What about a single link to hide and show an element?
<a href="javascript:shiftOpacity('digicam2', 1000)">show/hide</a>
It’s easy! With only a tiny bit of JavaScript! We’ll make another function named shiftOpacity(). It only requires two parameters:
- The element’s ID
- The duration of the transition in milliseconds.
This function does nothing more than checking whether the element is transparent and then calls the function opacity() to do the transition. This is what it looks like:
function shiftOpacity(id, millisec) {
//if an element is invisible, make it visible, else make it ivisible
if(document.getElementById(id).style.opacity == 0) {
opacity(id, 0, 100, millisec);
} else {
opacity(id, 100, 0, millisec);
}
}
source: http://brainerror.net/scripts/javascript/blendtrans/
javascript form validation
Monday, June 1st, 2009 by dreamluverzvalidateEmpty ( )
The function below checks if a required field has been left empty. If the required field is blank, we return the error string to the main function. If it’s not blank, the function returns an empty string.
function validateEmpty(fld) {
var error = “”;if (fld.value.length == 0) {
fld.style.background = ‘Yellow’;
error = “The required field has not been filled in.\n”
} else {
fld.style.background = ‘White’;
}
return error;
}
function validateUsername(fld) {
var error = “”;
var illegalChars = /\W/; // allow letters, numbers, and underscoresif (fld.value == “”) {
fld.style.background = ‘Yellow’;
error = “You didn’t enter a username.\n”;
} else if ((fld.value.length < 5) || (fld.value.length > 15)) {
fld.style.background = ‘Yellow’;
error = “The username is the wrong length.\n”;
} else if (illegalChars.test(fld.value)) {
fld.style.background = ‘Yellow’;
error = “The username contains illegal characters.\n”;
} else {
fld.style.background = ‘White’;
}
return error;
}
function validatePassword(fld) {
var error = “”;
var illegalChars = /[\W_]/; // allow only letters and numbersif (fld.value == “”) {
fld.style.background = ‘Yellow’;
error = “You didn’t enter a password.\n”;
} else if ((fld.value.length < 7) || (fld.value.length > 15)) {
error = “The password is the wrong length. \n”;
fld.style.background = ‘Yellow’;
} else if (illegalChars.test(fld.value)) {
error = “The password contains illegal characters.\n”;
fld.style.background = ‘Yellow’;
} else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
error = “The password must contain at least one numeral.\n”;
fld.style.background = ‘Yellow’;
} else {
fld.style.background = ‘White’;
}
return error;
}
function trim(s)
{
return s.replace(/^\s+|\s+$/, ”);
}function validateEmail(fld) {
var error=”";
var tfld = trim(fld.value);Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // value of field with whitespace trimmed off
var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;if (fld.value == “”) {
fld.style.background = ‘Yellow’;
error = “You didn’t enter an email address.\n”;
} else if (!emailFilter.test(tfld)) {Â Â Â Â Â Â Â Â Â Â Â Â Â //test email for illegal characters
fld.style.background = ‘Yellow’;
error = “Please enter a valid email address.\n”;
} else if (fld.value.match(illegalChars)) {
fld.style.background = ‘Yellow’;
error = “The email address contains illegal characters.\n”;
} else {
fld.style.background = ‘White’;
}
return error;}
if (fld.value == “”) {
error = “You didn’t enter a phone number.\n”;
fld.style.background = ‘Yellow’;
} else if (isNaN(parseInt(stripped))) {
error = “The phone number contains illegal characters.\n”;
fld.style.background = ‘Yellow’;
} else if (!(stripped.length == 10)) {
error = “The phone number is the wrong length. Make sure you included an area code.\n”;
fld.style.background = ‘Yellow’;
}
return error;
}
source: http://www.webcheatsheet.com/javascript/form_validation.php
javascript: escape()
Friday, May 22nd, 2009 by dreamluverzProblem: Getting error on ajax when passing url with “&” on it.
Solution: escape()
Definition and Usage
The escape() function encodes a string, so it can be read on all computers.
Syntax
| escape(string) |
| Parameter | Description |
|---|---|
| string | Required. The string to be encoded |
Tips and Notes
Note: The escape() function encodes special characters, with the exception of:
* @ – _ + . /
Tip: Use the unescape() function to decode strings encoded with escape().
Note: The escape() and unescape() functions should not be used to encode or decode URIs. Use encodeURI() and decodeURI() functions instead!
Example
In this example we use escape() to encode strings:
| <script type=”text/javascript”>
document.write(escape(“Visit W3Schools!”) + “<br />”); </script> |
The output of the code above will be:
Visit%20W3Schools%21
%3F%21%3D%28%29%23%25%26





