Monday, May 18, 2009

Difference between Javascript in head and body section

Hi folks, I had very little knowledge in Javascript. So far, I have been stealing the scripts from some Javascript sites & blogs and ofcourse, google helped me a lot ;). Felt little asahmed to search for simple and basic Javascripts. So, started reading JS from scratch. Better late than never :)

Alright, this is a most basic concept that I read. This post might looks silly and funny for JS gurus. But, it is valuable piece of information for a newbie like me. 

JS is a sequence of statements to be executed by the browser. It can be embedded both in <head> and <body> sections of the HTML document. Sometime, this puts us in dilemma and can be solved by knowing the difference between embedding them in the above sections. 

JS in <head> Section :
      Scripts in this section will be executed when called, or when an event is triggered. This will ensure that the script is loaded before anyone uses it.

Example:

<html>
   <head>
      <script type="text/javascript">
         function message()
           {
               alert(This message is defined in head section and called with onload event");
           }
      </script
>
   </head>

   <body onload="message()">
   </body>
</html>


JS in <body> Section :
     Scripts in this section will be executed while the page loads. 

Example:

<html>
   <head>  </head>
   <body>
      <script type="text/javascript">
         document.write("This message is displayed on page load");
      </script
>
   </body>
</html
>
   
The above written JS is page specific. If you want to use the same script in multiple pages, save it as a Javascript file(.js) and include in the <head> section using <script> tag.


gud luck :)

Wednesday, May 6, 2009

Connecting to external libraries using svn:externals

Subversion is a version control tool used by many software developers to manage changes within their source code as a version tree.

More often we tend to use external libraries in our project. While the external library is already versioned somewhere, storing them locally in our project's library is a mere waste of memory and we have to manually update our local copy everytime the external library gets updated.

To overcome this, SVN came up with a property called svn:externals. Let's consider a Zend Framework project where we need Zend library. I am going to connect to the lastest version of ZF, which is 1.8.0. 

In our application, the Zend library resides in "library/Zend" folder. The svn externals property is set on the parent folder (library) and will contain the value Directory RepositoryURL.

To set a property using TortoiseSVN, right click on the "library" folder, and select "TortiseSVN->Properties". From the properties dialog, click "Add" and select "svn:externals" from the Property value drop-down. In the value field, add  Zend http://framework.zend.com/svn/framework/standard/tags/release/1.8.0/library/Zend

Save and close the dialogue box. Now, do svn update on the "library" folder. This will create a folder called "Zend" inside "library" and will checkout the external repo.

You can connect to many external repositories from the same directory by adding each of them in newline.

Ciao :)

Wednesday, April 29, 2009

Setting up multiple virtual hosts on wamp in XP

This was something which needed desparately. Finally, I learnt how to setup multiple virtual hosts on WAMP. Here you go.

When you install WAMP, it gets installed as a package and the webroot pointing to
      C:\wamp\www.

1. Create a project directory, for example 
      C:/wamp/www/MyProject

2. Add the new host name in Windows hosts file located at
     C:\WINDOWS\System32\drivers\etc\hosts

     127.0.01 localhost
127.0.0.1 myproject

3. Edit the httpd.conf file to add path to virtualhosts definitions. In WAMP, by default this is line is commented. We have to uncomment the line and link it to correct file path.
       # Virtual hosts
         Include conf/extra/httpd-vhosts.conf

4. In httpd-vhosts, specify the mapping from MyProject folder to the new hostname.
       NameVirtualHost *:80

# this is the default mapping to http://localhost/ 
     <VirtualHost *:80>
         DocumentRoot C:\wamp\www 
         ServerName localhost 
     <\VirtualHost>

# this is the default mapping to http://myproject/ 
  &lt;VirtualHost *:80>
       DocumentRoot C:\wamp\www\MyProject\html 
      ServerName myproject
      <Directory "C:\wamp\www\MyProject>
           Options Indexes FollowSymLinks Includes 
          AllowOverride All 
          Order deny,allow 
           Deny from all
           Allow from 127.0.0.1 
             DirectoryIndex index.php 
         <\Directory>
<\VirtualHost>


5. Restart apache.

Good to go.

Hav fun :)

Wednesday, April 8, 2009

PHP - Introduction

In my few years of web programming, I have spent most of the time programming in PHP. Programming has gone through a drastic change from being procedural to Object Oriented. PHP as one of the web language, was/is never a stranger to these changes. 

PHP was conceived by Rasmus Lerdorf in 1994, written in C language. Intially, PHP stood for Personal Home Page, which was later changed by two Isreli developers Zeev Suraski and Andi Gutmans in 1997. They rewrote the scripting language and formed the base of PHP3, changing the name PHP to Hypertext Preprocessor. PHP was used for embedding a set of executable scripts in the web page. In late 1998, Zeev and Andi felt that they could have written the language in a much better way and came up with PHP4, which followed a new paradigm "compile first and execute later". The compliation step does not compile PHP script into machine code, instead compiles into byte code which is executed by Zend Engine. It became a full fledged system, offering flexibilty as any other web based programming language. An Object Model was also introduced with few quirks and limitations. 

The release of PHP5 came up with the revised Object Oriented part of Zend Engine, which made  PHP5, a matured programming language. Not only does it revolutionize PHP's Object Oriented support, but also the new extensions like SimpleXML, MYSQLi, SOAP, etc., made it the ultimate web development platform.

Let us discuss more in detail about advanced object oriented features of PHP5 in the forthcoming  posts.

Happy PHP'ing !!!