Sunday, December 20, 2009

Install WAMP server

The WAMP server is one of the most important, easy to install and successful tool in making up the most of the free features. Also helps to learn PHP and can be used as a building stone.

WAMP server can be downloaded from http://www.wampserver.com/en/download.php and installed as per the directions.

On Installation , you can specify a directory as C:/WAMP for installation path, so that people using VISTA dont have to struggle with Admin rights each time , as is the case if installed in Program Files. Its just a suggestion and you may use any method you want.

Once the installation is completed, open the default internet browser , and type http://localhost or http://localhost:80

WAMP homepage should come up.

In case the WAMP homepage is missing, check the system tray for WAMP icon , right click and select "PUT ONLINE" , or an option that appears to be like that (like start all services) .

Once the homepage displays (http://localhost) WAMP server , WAMP is ready and you are ready to go for your PHP code

Wednesday, June 10, 2009

Interview Questions And Answers in PHP

1. What are the differences between Get and post methods in form submitting, give the case where we can use get and we can use post methods?

Ans: Using HTML we use form to submit the values. Click here to know more about HTML forms. Get is used to pass the data using URL , and we can send a particular length of characters as supported by the explorer.
When we use POST method , we can send the unlimited length of data using POST.

Action is used to submit the form , and the elements in the form get in array as $_POST, $_GET and $_REQUEST

Tuesday, April 7, 2009

Operators in PHP

Just like any other programing language , PHP comes with its own set of operators. they might look similar to behave in same way as any java or c# operator. But we will look into the operators as they might be some variations. There are different types of operators in PHP : 
  1. Arithematic operators
  2. Assignment operators
  3. comparison operators 
  4. Logical operators 
Arithermatic operators : Throughout the history , the first things we learned we learned were alphabets and numbers. Then we have added ages to the life, subtracted the shortcomings ,and multipliedz our experience in life. All these operations in PHP are carried with a rich set of arithematic tools it has to offer. Below is a table which lists the various PHP operators : 

Operator

Description

Example

Result

+

Addition

$iknowjavaAdd=2
$iknowjavaAdd+20

22

-

Subtraction

$iknowjavaSub=29
$50-
iknowjavaAdd

21

*

Multiplication

$iknowjavaMultiply=54

$iknowjavaMultiply*2

108

/

Division

15/5
5/2

3
2.5

%

Modulus (division remainder)

5%2
10%8
10%2

1
2
0

++

Increment

$iknowjavaInc=59

$iknowjavaMultiply++

x=60

--

Decrement

$iknowjavaDec=90

$iknowjavaDec--

x=89


----------------------------------------------------------------------------------------------------------------------------------------
Assignment operators 
----------------------------------------------------------------------------------------------------------------------------------------
Assignment operators : Many times we have looked into assignement operators. This is a new beginning for many. If i want to put a value of 5 in a variable $iknowmyjava, then I will have to find a way to do it. I will use "=" sign . 
Such type of operations are handled by assignment operators. A few PHP operators are listed below : 

Operator

Example

Is The Same As

=

$x=$y

$x=$y

+=

$x+=$y

$x=$x+$y

-=

$x-=$y

$x=$x-$y

*=

$x*=$y

$x=$x*$y

/=

$x/=$y

$x=$x/$y

%=

$x%=$y

$x=$x%$y


----------------------------------------------------------------------------------------------------------------------------------------
Comparison operators 
----------------------------------------------------------------------------------------------------------------------------------------

Operator

Description

Example

==

is equal to

5==8 returns false

!=

is not equal

15!=18 returns true

> 

is greater than

15>18 returns false

< 

is less than

51<81>

>=

is greater than or equal to

51>=81 returns false

<=

is less than or equal to

51<=81 returns true


----------------------------------------------------------------------------------------------------------------------------------------
Logical operators 
----------------------------------------------------------------------------------------------------------------------------------------

Operator

Description

E$xample

&&

and

$x=6
$y=3

($x <> 1) returns true

||

or

$x=6
$y=3

($x==5 || $y==5) returns false

!

not

$x=6
$y=3

!($x==$y) returns true

Monday, April 6, 2009

Data Storage in PHP

Data is stored in variables in any programing language. The variables declared in PHP are a bit different than other programing languages. Each variable name starts with "$" sign. If I like to name a variable as iknowPHP variable , it will throw an error. 
The way to declare a variable in PHP is simple though.
$iknowjava = 5;
$iknowmyjava ="Deepak";

Few points : 
  1.  Variable name can start with $ only
  2. Variable name can have only alphabets or numbers or underscore or combinatiion of these three. Spaces in variable names are not permitted
 Once done with the variables , PHP will itself decide on what variable it is , whether its a string variable , a char or a number , depending on the value it has. 

So we will move to next important part in PHP , the various operators.

Writing the first Code

Now we are well set to make the first program. Or the web application. Lets start. 
Go to Location :
C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs 

Or find the folder named htdocs in Apache installation folder. 

Open the text editor / Textpad. 
This can be done by right clicking in any folder --> New --> Text File.

Now write the following code in the the notepad: 

Save this File as iknowPHP.php in the HTMLDOCS folder in Apache. 
Make sure you have not saved it as iknowPHP.php.txt  . 
Run the script . How to do that :

Running the first script: 
Open IE and type :
If the page says  : It works , then we are right into running the first script. Just append the address with iknowPHP.php and hit enter
http://localhost/iknowPHP.php

The script should run. In case the explorer asks to save the file , then please go through installation steps once more for correct installation. 
Do visit www.iknowjava.com for more codes in PHP / JAVA and C#




Thursday, February 26, 2009

Configuring The Apache Web server to PHP

Now we want to configure the apache web server to the php so that we will be able to use this code for developement of the code locally. 
First step is to type 
http://localhost on the web browser. 

Now Go to Server directory , which is in C:/Program folders / Apache .
Now if you have app servers installed , these will also be located in the same folder, make sure u select the web server ( version 2.2) and not tomcat . 

Now go to Conf folder and locate the file httpd.conf 

Open the file and search for "#LoadModule" . Once you find the LoadModule, append the last line in the same para with the following value :
"#LoadModule php5_module c:/php5apache2_2.dll" 

Now search for "AddType" and add 
"AddType application/x-httpd-php .php"

restart server :)

Saturday, January 24, 2009

Chapter 2.2 - Verifying Installed Apache

Now we need to checke whether Apache is running or not.  There are two ways to verify whether the Apache is installed. 
 Go to Start -> and types services.msc in Run prompt .  Select the services as shown.


Once Service is selected , there is a process named Apache2.2 listed. If you can see the process , then Apache is installed. If its running successfully , just double click the Apache2.2 . You will get the pop up

Click on Start . If the service is changed to Started , as shown below , Start will become disabled , and Services will be started. 
Congratulations . Apache is installed on the system. 

Second Way to Use and Verify Apache 

Go to Programs ,  navigate to Apache 2.2 and click the selected server.
An  icon appears in the taskbar as shown. Double click on it . 
 
The dialog box opens. Click on Start , and if its running , Congratulations , your APACHE Web Server is installed 

Once we are done with the Apache installation , we need to verify its working .

Chapter 2.1 - Install Apache

Now the next thing to do is to install Webserver.  Go to 
http://httpd.apache.org/ and select the file in section : "Apache 2.2.11 Released".
Please download the file as shown in the link only. Please Give attention to File being Targetted to Download in next section , as wrong file can get you in troubled waters . 
  
Once you click on the download link , you will be directed to another site. Download the file named 
"Win32 Binary without crypto (no mod_ssl) (MSI Installer): apache_2.2.11-win32-x86-no_ssl.msi [PGP] [MD5]
The same is highlighted in the screen shot. 

Once you download the file , double click on the file . Fill in the basic information . 
In case , you are prompted to ask server host , you can type in localhost . 

Click Next ,and you will be through. Apache is installed. Verifying Apache is installed : 
  1. Go To Program Files. C:/Program Files. Look for folder named "Apache Software Foundation". But in case you have recently got a new 64 bit processor you might just not see the folder mentioned above. I  also faced the same problem. I was unable to locate the Aoache folder in first place. There can be two basic reasons for the Apache server not present in th folder 
1. The installation was not successful 
2. The laptop is 64 bit , and has a different program file folder.   
The second program File folder is named as Program Files (x86). This has all the files compatible with 32 bit processoe r.
 
 ( Continued) 

Chapter 1 - Install PHP

The first step  to install PHP is to download the software. 
Go to http://www.php.net/downloads.php and select the Windows Binary File for Download. The file you need to install is highlighted in the screenshot.  
Once You select the file for download , you will be directed to the mirror image. The file size is approx 10 MB. Select the server near to your country. This helps in faster download. 

Once you have downloaded the file . Do the following Steps: 

  1. Create a new folder named php in C: ( C Drive). 
  2. Extract the contents of the file in C:/php.
PHP is now installed. But there are two more things to do before you can run the PHP actually on your system. 
  1. Install Web Server 
  2. Configure Web server to PHP.
These will be covered in next chapter 


Pre Installing PHP

PHP for Laptop : 
Now i have Vista Home Edition , and look forward to make my PHP scripts working. Its a laptop , and no webserver. 
Problems to be addressed as of now are : 
1. Use of Web server , and how to install it. 
2. Use of config directory 
3. Downloading PHP latest version
4. Integrating PHP with Apache Server ( web server) 
5. Running the first Program .

PHP is one of the fastest growing scripting language . 
 Need of Web server : Since PHP is web server it will execute the scripts on the server side. So server is needed. There can be two ways to run PHP , if you have a domain name , and bought server space with it , and PHP is installed on the the server . Or you want to run it on your system , you need to install webserver. One may use IIS or Apache. 

I will be using  Apache as the web server. 
Please note all the software used are freeware .... and please tell if there is any problem,. Next few sessions will be to install the PHP on the Laptop. Please Feel Free to ask me of any doubts. 

I will be segregating each install as each chapter, so that you are not confused. Follow it chapter wise and you will be able to install PHP on your machine.  

Please go According to Chapters.