Thursday, April 30, 2009

Alternative to classic LightBox - Sexy LightBox 2.1

Sexy LightBox 2.1 is a lightweight and elegant replacement for classic Lightboxes you use. Comes with a MIT license and very easy to integrate.

Sexy LightBox

http://www.coders.me/ejemplos/sexy-lightbox-2/

Tuesday, April 28, 2009

How to check upload file extension (JavaScript)

Before uploading a file it's a good idea to check for valid file extensions you want.
Even though you can easily bypass JavaScript validation by disabling JavaScript in the browser, you can prevent genuine user errors by implementing this code.


<html>
<head>
<title>Upload Check</title>
<script type="text/javascript">

function vali_type()
{
var id_value = document.getElementById('up').value;

if(id_value != '')
{
var valid_extensions = /(.jpg|.jpeg|.gif)$/i;
if(valid_extensions.test(id_value))
{
alert('OK');
}
else
{
alert('Invalid File')
}
}
}


</script>
</head>

<body>

<input type="file" name="up" id="up"
onBlur="vali_type()" />

</body>
</html>



var valid_extensions = /(.jpg|.jpeg|.gif)$/i;
Check for .jpg, .jpeg and .gif file extentions in the end of the string
| - OR
i - Case Insensitive
$ - END

Monday, April 27, 2009

mysql_real_escape_string() is not working properly

Is the function mysql_real_escape_string() return a empty value for you? or does it not work properly as you expected.
The most common mistake is the use of the mysql_real_escape_string() before a database connection.
Make sure you use the function after a successful database connection.

If E_WARNING error level is enabled in your error_reporting you will get a E_WARNING for this mistake. It's always a good idea to make error_reporting E_ALL in the development cycle.

http://www.php.net/mysql_real_escape_string

Read the Notes section for more details.

Saturday, April 11, 2009

List of Browser User Agents to use with php curl

Here is a simple list of user agents that can be used with php curl or JavaScript

(In windows)

IE 7 - Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SU 3.21; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)

Chrome - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.53 Safari/525.19

Firefox 3.0 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8

Firefox 2.0 - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6

Safari - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.28 (KHTML, like Gecko) Version/3.2.2 Safari/525.28.1

Opera - Opera/10.00 (Windows NT 5.1; U; en) Presto/2.2.0

Sunday, April 5, 2009

Wedding of two SLIIT Batchmates

How fast the time pass by. 3 years ago we were so free. Now we have been sucked into the race of making money and to the Zombie Theory ;-)

This photo was taken around 2006

SLIIT Group Project Team

This is now 2009 April



I wish all the best for Shiksha and Saveen.

Wednesday, April 1, 2009

Get php time diff (time diffence)

Following code will show you how to get time difference in second from a two datetime values. Remember datetime should be in this format: yyyy-mm-dd hr:min:sec

$dbdate_seconds = strtotime($dbdate);
$inputdate_seconds = strtotime($inputdate);

$time_diff = $dbdate_seconds - $inputdate_seconds;

//you will get the time difference in seconds, divide by 60 to make it minutes

or you can use the mysql TIMEDIFF

$query = select TIMEDIFF(field_name, '$input_date') from tbl_name where condition