Validate Email
We can perform an email validation through this function.
1 | function isValidEmail( $email ){ |
2 | return eregi ( '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$' , $email ); |
After fainted for a few seconds when i saw unreal4u finding, i decided to throw up preg_match solution instead.
1 | function isValidEmail( $email ){ |
2 | return preg_match( '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i' , $email ); |
PHP 5.2 and above.
1 | function fnValidateEmail( $email ) |
3 | return filter_var( $email , FILTER_VALIDATE_EMAIL); |
Sanitize Email
We can further sanitize our email to ensure that everything is alright.
1 | function fnSanitizeEmaill( $string ) { |
2 | return preg_replace( '((?:\n|\r|\t|%0A|%0D|%08|%09)+)i' , '' , $string ); |
PHP 5.2 and above.
1 | function fnSanitizeEmaill( $url ) |
3 | return filter_var( $url , FILTER_SANITIZE_EMAIL); |
Validate Email Exist
This is not possible but certain validation can be use to validate email existence.
01 | function check_email( $email ) |
04 | $Email = htmlspecialchars( stripslashes ( strip_tags (trim( $email )))); |
05 | if ( $Email == '' ) { email_error = true; } |
06 | elseif (! eregi ( '^([a-zA-Z0-9._-])+@([a-zA-Z0-9._-])+\.([a-zA-Z0-9._-])([a-zA-Z0-9._-])+' , $Email )) { email_error = true; } |
08 | list( $Email , $domain ) = split( '@' , $Email , 2); |
09 | if (! checkdnsrr ( $domain , 'MX' )) { email_error = true; } |
11 | $array = array ( $Email , $domain ); |
12 | $Email = implode( '@' , $array ); |
16 | if (email_error) { return false; } else { return true;} |
Validate Number Only
We can use PHP built-in function to validate whether a given value is a number.
1 | function fnValidateNumber( $value ) |
7 | return is_numeric ( $value ); |
PHP 5.2 and above.
1 | function fnValidateNumber( $value ) |
3 | # return filter_var( $value , FILTER_VALIDATE_FLOAT); |
4 | return filter_var( $value , FILTER_VALIDATE_INT); # int |
Sanitize Number
We can force all value to be only numeric by sanitize them.
1 | function fnSanitizeNumber( $str ) |
3 | #letters and space only |
4 | return preg_match( '/[^0-9]/' , '' , $str ); |
PHP 5.2 and above.
1 | function fnSanitizeNumber( $value ) |
3 | # return filter_var( $value , FILTER_SANITIZE_NUMBER_FLOAT); |
4 | return filter_var( $value , FILTER_SANITIZE_NUMBER_INT); # int |
Validate String Only
Sometimes to validate name we can use this function to restrict only letters and spaces.
1 | function fnValidateStringr( $str ) |
3 | #letters and space only |
4 | return preg_match( '/^[A-Za-z\s ]+$/' , $str ); |
Sanitize String
We can sanitize it instead of validate user input.
1 | function fnSanitizeStringr( $str ) |
3 | #letters and space only |
4 | return preg_replace( '/[^A-Za-z\s ]/' , '' , $str ); |
PHP 5.2 and above. built-in function by PHP provides a much more powerful sanitize capability.
1 | function fnSanitizeStringr( $str ) |
3 | return filter_var( $str , FILTER_SANITIZE_STRIPPED); # only 'String' is allowed eg. '<br>HELLO</br>' => 'HELLO' |
Validate Alphanumeric Characters
This validates alphanumeric characters.
1 | function fnValidateAlphanumeric( $string ) |
3 | return ctype_alnum ( $string ); |
Sanitize Alphanumeric Characters
This sanitize alphanumeric characters. eg. “HELLO! Do we have 90 idiots running around here?” => “HELLO Do we have 90 idiots running around here”
1 | function fnSanitizeAlphanumeric( $string ) |
3 | return preg_replace( '/[^a-zA-Z0-9]/' , '' , $string ); |
Validate URL Exist
This function will check whether a given URL exist and not only validate it.
01 | function url_exist( $url ) |
03 | $url = @ parse_url ( $url ); |
10 | $url = array_map ( 'trim' , $url ); |
11 | $url [ 'port' ] = (!isset( $url [ 'port' ])) ? 80 : (int) $url [ 'port' ]; |
12 | $path = (isset( $url [ 'path' ])) ? $url [ 'path' ] : '' ; |
19 | $path .= (isset( $url [ 'query' ])) ? '?$url[query]' : '' ; |
21 | if (isset( $url [ 'host' ]) AND $url [ 'host' ] != @ gethostbyname ( $url [ 'host' ])) |
25 | $headers = @get_headers( '$url[scheme]://$url[host]:$url[port]$path' ); |
29 | $fp = fsockopen ( $url [ 'host' ], $url [ 'port' ], $errno , $errstr , 30); |
35 | fputs ( $fp , 'HEAD $path HTTP/1.1\r\nHost: $url[host]\r\n\r\n' ); |
36 | $headers = fread ( $fp , 4096); |
39 | $headers = ( is_array ( $headers )) ? implode( '\n' , $headers ) : $headers ; |
40 | return (bool)preg_match( '#^HTTP/.*\s+[(200|301|302)]+\s#i' , $headers ); |
Validate URL Format
This function will validate a given url to ensure the format is correct.
1 | function fnValidateUrl( $url ){ |
2 | return preg_match( '/^(http(s?):\/\/|ftp:\/\/{1})((\w+\.){1,})\w{2,}$/i' , $url ); |
PHP 5.2 and above.
1 | function fnValidateUrl( $url ) |
3 | return filter_var( $url , FILTER_VALIDATE_URL); |
Sanitize URL
PHP 5.2 and above.
1 | function fnSanitizeUrl( $url ) |
3 | return filter_var( $url , FILTER_SANITIZE_URL); |
Validate Image Exist
This function will check whether a given image link exist and not only validate it.
1 | function image_exist( $url ) { |
2 | if (@ file_get_contents ( $url ,0,NULL,0,1)){ return 1;} else { return 0;} |
Validate IP Address
This function will validate an IP address.
1 | function fnValidateIP( $IP ){ |
2 | return preg_match( '/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/' , $IP ) |
PHP 5 and above. This can also specific validation for IPV4 or IPV6.
1 | function fnValidateIP( $ip ) |
3 | return filter_var( $ip , FILTER_VALIDATE_IP); |
Validate Proxy
This function will let us detect proxy visitors even those that are behind anonymous proxy.
01 | function fnValidateProxy(){ |
02 | if ( $_SERVER [ 'HTTP_X_FORWARDED_FOR' ] |
03 | || $_SERVER [ 'HTTP_X_FORWARDED' ] |
04 | || $_SERVER [ 'HTTP_FORWARDED_FOR' ] |
05 | || $_SERVER [ 'HTTP_VIA' ] |
06 | || in_array( $_SERVER [ 'REMOTE_PORT' ], array (8080,80,6588,8000,3128,553,554)) |
07 | || @ fsockopen ( $_SERVER [ 'REMOTE_ADDR' ], 80, $errno , $errstr , 30)) |
09 | exit ( 'Proxy detected' ); |
Validate Username
Before we validate whether a given username is matches the one in our database, we can perform a validation check first to prevent any unnecessary SQL call.
1 | function fnValidateUsername( $username ){ |
2 | #alphabet, digit, @, _ and . are allow. Minimum 6 character. Maximum 50 characters (email address may be more) |
3 | return preg_match( '/^[a-zA-Z\d_@.]{6,50}$/i' , $username ); |
Validate Strong Password
Another good thing is to validate whether a particular password given by the user is strong enough. You can do that using this function which required the password to have a minimum of 8 characters, at least 1 uppercase, 1 lowercase and 1 number.
1 | function fnValidatePassword( $password ){ |
2 | #must contain 8 characters, 1 uppercase, 1 lowercase and 1 number |
3 | return preg_match( '/^(?=^.{8,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$/' , $password ); |
Validate US Phone Number
This function will validate US phone number for US users.
1 | function fnValidateUSPhone( $phoneNo ){ |
2 | return preg_match( '/\(?\d{3}\)?[-\s.]?\d{3}[-\s.]\d{4}/x' , $phoneNo ); |
Validate US Postal Code
This function validate US postal code.
1 | function fnValidateUSPostal( $postalcode ){ |
3 | return preg_match( '/^([0-9]{5})(-[0-9]{4})?$/i' , $postalcode ); |
Validate US Social Security Numbers
This function validate US Social Security Numbers.
1 | function fnValidateUSSocialSecurityCode( $ssb ){ |
3 | return preg_match( '/^[\d]{3}-[\d]{2}-[\d]{4}$/' , $ssn ); |
Validate Credit Card
This function validate credit card format.
1 | function fnValidateCreditCard( $cc ){ |
3 | return preg_match( '/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$/' , $cc ); |
Validate Date
This is a date format MM-DD-YYYY or MM-DD-YY validation which validate from year 0000-9999.
1 | function fnValidateDate( $date ){ |
6 | return preg_match( '/^((0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.][0-9]?[0-9]?[0-9]{2})*$/' , $date ); |
This is a date format YYYY-DD-MM or YY-MM-DD validation which validate from year 0000-9999.
1 | function fnValidateDate( $date ){ |
6 | return preg_match( '#^([0-9]?[0-9]?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01]))*$#' ', $date ); |
Validate Hexadecimal Colors
This is a good validation for people who allows their user to change color in their system.
1 | function fnValidateColor( $color ){ |
5 | return preg_match( '/^#(?:(?:[a-f0-9]{3}){1,2})$/i' , $color ); |
Make Query Safe
This function help sanitize our data to be SQL injection safe.
2 | return is_array ( $str ) ? array_map ( '_clean' , $str ) : str_replace ( '\\' , '\\\\' , htmlspecialchars((get_magic_quotes_gpc() ? stripslashes ( $str ) : $str ), ENT_QUOTES)); |
Make Data Safe
This function help to keep us protected against XSS, JS and SQL injection by removing tags.
2 | return is_array ( $str ) ? array_map ( '_clean' , $str ) : str_replace ( '\\' , '\\\\' , strip_tags (trim(htmlspecialchars((get_magic_quotes_gpc() ? stripslashes ( $str ) : $str ), ENT_QUOTES)))); |
Open Source Flash Media Server
0_9_1 – Red5:
KLOTH.NET – about radio and internet, DNS lookup, whois, antispam:
Online Tools and Services
- Find your IP address, and what are your browser settings.
- nslookup : DNS lookup to query a domain name server to look up and find IP address information of computers in the internet. As the use of nslookup is deprecated, using dig is recommended instead (see below).
- dig DNS lookup : query a domain name server to look up and find IP address information of computers in the internet.
- whois lookup : query a WHOIS server to look up and find internet domain registration data.
- iplocate : translate/convert an IP V4 address between dotted quad, decimal, hex and binary, do a PTR reverse lookup in the DNS, and search for location information.

- ping : to ping a distant internet host to see if it is active or reachable from this host.
- traceroute : trace the route to a distant internet host.
- Use serverinfo to query a web server to see from the received HTTP header what server software is running.
- Use Multi DNSBL-check to look up an internet IP v4 address to see if it is blacklisted on public blackhole lists as known spam source.
- Selcall, translate selcalls of the Maritime Mobile Service (MMS).
- Cardpunch, punch a card.
- TTYpunch, punch a perforated ITA2/Baudot teletype tape.
- Get a Fortune Cookie.
- Get Date and Time live from an NTP-server.
- Datum, date calculations and translations.