Monday, November 2, 2009
My New Site [ http://silversurferslab.com/ ]
You can visit my new website in http://silversurferslab.com/. I'm currently in the process of adding my old blog articles to my new site. See you there.
Friday, October 16, 2009
Customize ReCaptcha theme
ReCaptcha is a widely use Captcha generation web service which is owned by Google. Yesterday I had the opportunity to use ReCaptcha for one of my project. But there was a problem. Since ReCaptcha is generated to a certain style, width and height using a webservice request, it was hard to put it into the design of the form which I was trying to integrate ReCaptcha.
But finally I could solve the problem using some tricks. This is how I did it.
For using ReCaptcha, first you have to create an account ( account and service is free) in http://recaptcha.net/ and generate a public key and a private key for accessing ReCaptcha web service. You can choose two option when generating those keys, default is generated keys can only be used in provided ( when generating keys) web site. Other one is you can use generated keys in any server and you have to select the checkbox saying some global key enabling ( I can't remember it) for using this second option.
Then download the ReCaptcha library. It contains recaptchalib.php files and an example page. What do you want is recaptchalib.php. To use recaptcha, add following php codes in to the top of your php page.
require_once('recaptchalib.php');
$publickey = "your_public_key"; // get this from the signup page
$privatekey = "your_private_key";// get this from the signup page
Since you are looking for custom theme for ReCaptcha, add this javascript code to head section of the your php page.
<script type= "text/javascript">
var RecaptchaOptions = {
theme: 'custom',
lang: 'en',
custom_theme_widget: 'recaptcha_widget'
};
</script>
Value of "custom_theme_widget" which is 'recaptcha_widget' in above code is the name of the div which your recaptcha gadget will put into.
Then add a div with the above mentioned id 'recaptcha_widget' in to the place where you need your recaptcha. All other recaptcha related divs will reside in this created div. Add another div named 'recaptcha_image' inside 'recaptcha_widget' for holding the recaptcha image. You also need to add a input text field named 'recaptcha_response_field' for typing the letters in the captcha image. There are lot of other things you can put as your requirements as a link for audio recaptcha, for error messages, for refreshing recaptcha etc, and I'm not going to put all those things in my example. In addition to that, you also have to put code for getting recaptcha with your publick key (two parts of code, if javascript is disabled, there is an iframe to include).
So this is the code I finally got as ReCaptcha widget,
<div id="recaptcha_widget" style="display: none;">
<div id="recaptcha_image"></div>
<div class="recaptcha_only_if_incorrect_sol" style="color: red;">Incorrect please try again</div>
<span class="recaptcha_only_if_image">Enter the words above:</span>
<span class="recaptcha_only_if_audio">Enter the numbers you hear:</span>
<input id="recaptcha_response_field" name="recaptcha_response_field" type="text">
<strong style="font-size: 10px;"><a href="javascript:void(0);">Get another CAPTCHA</a></strong>
<!--div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')">Get an audio CAPTCHA</a></div><br />
<div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type('image')">Get an image CAPTCHA</a></div><br /><br />
<div><a href="javascript:Recaptcha.showhelp()">Help</a><br />
</div-->
<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=<?php echo $publickey;?>&lang=en"></script>
<noscript>
<iframe src="http://api.recaptcha.net/noscript?k=<?php echo $publickey;?>&lang=en" height="200" width="500" frameborder="0"></iframe>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="'hidden'" name="'recaptcha_response_field'" value="'manual_challenge'">
</noscript>
</div>
I commented out some fields I did not want to use in this code. After coding to this point, there was another problem came. That is the image generated by ReCaptcha is a standarad size of 300px X 57px. By adding a little css code, I could change the size of the recaptcha image as I wanted. I added following CSS code into the head section ( between head tags) of my php page.
<style type="text/css">
div#recaptcha_image > img{
height:46px;
width:240px;
}
</style>
This is the final output of the code.
But finally I could solve the problem using some tricks. This is how I did it.
For using ReCaptcha, first you have to create an account ( account and service is free) in http://recaptcha.net/ and generate a public key and a private key for accessing ReCaptcha web service. You can choose two option when generating those keys, default is generated keys can only be used in provided ( when generating keys) web site. Other one is you can use generated keys in any server and you have to select the checkbox saying some global key enabling ( I can't remember it) for using this second option.
Then download the ReCaptcha library. It contains recaptchalib.php files and an example page. What do you want is recaptchalib.php. To use recaptcha, add following php codes in to the top of your php page.
require_once('recaptchalib.php');
$publickey = "your_public_key"; // get this from the signup page
$privatekey = "your_private_key";// get this from the signup page
Since you are looking for custom theme for ReCaptcha, add this javascript code to head section of the your php page.
<script type= "text/javascript">
var RecaptchaOptions = {
theme: 'custom',
lang: 'en',
custom_theme_widget: 'recaptcha_widget'
};
</script>
Value of "custom_theme_widget" which is 'recaptcha_widget' in above code is the name of the div which your recaptcha gadget will put into.
Then add a div with the above mentioned id 'recaptcha_widget' in to the place where you need your recaptcha. All other recaptcha related divs will reside in this created div. Add another div named 'recaptcha_image' inside 'recaptcha_widget' for holding the recaptcha image. You also need to add a input text field named 'recaptcha_response_field' for typing the letters in the captcha image. There are lot of other things you can put as your requirements as a link for audio recaptcha, for error messages, for refreshing recaptcha etc, and I'm not going to put all those things in my example. In addition to that, you also have to put code for getting recaptcha with your publick key (two parts of code, if javascript is disabled, there is an iframe to include).
So this is the code I finally got as ReCaptcha widget,
<div id="recaptcha_widget" style="display: none;">
<div id="recaptcha_image"></div>
<div class="recaptcha_only_if_incorrect_sol" style="color: red;">Incorrect please try again</div>
<span class="recaptcha_only_if_image">Enter the words above:</span>
<span class="recaptcha_only_if_audio">Enter the numbers you hear:</span>
<input id="recaptcha_response_field" name="recaptcha_response_field" type="text">
<strong style="font-size: 10px;"><a href="javascript:void(0);">Get another CAPTCHA</a></strong>
<!--div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')">Get an audio CAPTCHA</a></div><br />
<div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type('image')">Get an image CAPTCHA</a></div><br /><br />
<div><a href="javascript:Recaptcha.showhelp()">Help</a><br />
</div-->
<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=<?php echo $publickey;?>&lang=en"></script>
<noscript>
<iframe src="http://api.recaptcha.net/noscript?k=<?php echo $publickey;?>&lang=en" height="200" width="500" frameborder="0"></iframe>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="'hidden'" name="'recaptcha_response_field'" value="'manual_challenge'">
</noscript>
</div>
I commented out some fields I did not want to use in this code. After coding to this point, there was another problem came. That is the image generated by ReCaptcha is a standarad size of 300px X 57px. By adding a little css code, I could change the size of the recaptcha image as I wanted. I added following CSS code into the head section ( between head tags) of my php page.
<style type="text/css">
div#recaptcha_image > img{
height:46px;
width:240px;
}
</style>
This is the final output of the code.
Tuesday, September 1, 2009
Use uppercase letters for mysql data table names in Windows
When we developing mysql based applications, there is a good probability to developers develop the application on Windows OS and deploy it on a linux server or vice versa. MySQL supports both lowercase and uppercase letters for table names in unix enviroments, but when it came to Windows, the default MySQL configuration does not support upper case letters in table names. This becomes a big headache if you need to restore mysql database backups from windows environments to unix environments ( other way round is not quiet a problem since all table names becomes lowercase in Windows machines) during several times while development.
Today I found a solution for this case insensitvity of table names in MySQL servers on Windows environment. There is a mysql system variable called "
Related MySQL articles,
http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_lower_case_table_names
Today I found a solution for this case insensitvity of table names in MySQL servers on Windows environment. There is a mysql system variable called "
lower_case_table_names" and it has set to 1 in default mysql configuration for Windows. 1 means only lower case table names are supported. For gaining the support for Both lower and upper case letters in table names, what you have to do is find relevant my.ini file for your MySQL installation and add the following line to the end of the file.lower_case_table_names=2Then restart the MySQL server. Now you will be able to create tables with names which include both upper-case and lower-case letters.Related MySQL articles,
http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_lower_case_table_names
Saturday, July 18, 2009
Searching a MySql database for a Value to find which tables contains it.
In my recent works, I needed to do a search for a some string value to find what are the tables contains that value. Although there are easy tools and methods which allows you to search for a value in a known field and known data table, I couldn't found a easy way to search for a value in a entire MySQL database. So i wrote this simple PHP script for accomplished that task. If somebody needs such functionality, they can use the script. Please change the database host, user name, password ( and database name ) according to your requirements.
This scripts helps to search a value in an entire mysql database. In main results page, it will displays the tables which contains the search value and what are the fields which contains the search value and number of occurences of the search value. By clicking on the number of results column value in the main results table, You can go to a page which displays the rows which contains the search value in relevant database table.
Download it from
http://heidisoft.com/sites/default/files/phpmysearch.zip
or
http://rapidshare.com/files/257172086/phpmysearch.zip
This scripts helps to search a value in an entire mysql database. In main results page, it will displays the tables which contains the search value and what are the fields which contains the search value and number of occurences of the search value. By clicking on the number of results column value in the main results table, You can go to a page which displays the rows which contains the search value in relevant database table.
Download it from
http://heidisoft.com/sites/default/files/phpmysearch.zip
or
http://rapidshare.com/files/257172086/phpmysearch.zip
Labels:
mysql,
php,
search tool
| Reactions: |
Sunday, July 5, 2009
Reset passwords for XAMPP pages
When I installed XAMPP on UBUNTU OS in my laptop, I put a password for that. But unfortunately , I couldn't remember it later. So I did some search on it and found a solution for the problem.
Open a terminal and type following command,
Open a terminal and type following command,
sudo /opt/lampp/lampp securityThen it will ask for new password and no need to provide old passwords.
Thursday, June 18, 2009
Thursday, May 21, 2009
A nice song for a great leader - Ayubowewa Maha Rajanane
This is one of my favorite song. It is written for our great president Mahinda Rajapaksha. He has all characteristics of a great king as mentioned in this song. We are very lucky to have such a great leader.
Labels:
Mahinda Rajapaksha,
Song
| Reactions: |
Subscribe to:
Posts (Atom)



