Wednesday, July 13, 2011

introduction to server scripting (php)

as we all about programming but web programming is a little different thing.
computer you are using to view this webpage is a client and server is that provided you this webpage.
what is really a client and server script?
a client script is a program that runs on the browser.
a server script is a program that run on the server.
client scriptsJavaScript,vb script,css and many more
server scriptsphp,asp,jsp and many more

server script's run on server and can be used to store your name password email and other details.
and you can access those resource from any part of the world
and client scripts are used for make page more interactive.
if you use client script for storing data you can only access that data from the specific computer only

once the server script is finished on the server the data is send to the client

i recommend php because its open source and full of feature..
hundred's of predefined function and constants.

for storing data the best option is MySQL

programmers say that php and MySQL is a very strong combination for server scripting

example of php+MySQL
yahoo,Facebook and many more out there..

php is easy to learn and a very powerful language.
if you know c or c++ you will find php even more easy as syntax and function names are similar


http://php.net is the official site for php documentation.

php official site contains all the function documentation for reference and great examples for beginners and troubleshoot


to make a php page use the extension .php
inside the file start with
<?php
   ---php codes-----
   ---php codes-----
?>
"<?php" is used to start a php script
"?>" is used to end a php script


comments in php
<?php
    $var1="hello"; #comment 1
    $var2="how are you?"; //comment 2
    $var3="nice to meet you"; /*this is
      is a multi line comment
      you can you chose as many line
      for comment till you end it similar to c++ syntax */
?>


variables in php
variable in php start with the dollar sign and cannot start with a number
there are no reserved keywords in php like c++
no space between character is allowed
example
correct names$var,$hello_word,$class,$integer
incorrect namesvar,$var one

$var1="hello"; /*var1 contain string value "hello"*/
$var=10; /*var2 contain integer value 10*/
$var=new array(); /*create an array,more discussion on it later*/


printing a variable value in php
<?php
    $nuke="this is all about nuclear reactor's";
    echo $nuke; /*echo $nuke prints the string*/
?>
output:-

this is all about nuclear reactor's


operations on variable
<?php
    $var1=10;
    $var2=5;
    $result=0;               /*to set the result 0*/
    $result=$var1 + $var2;   /*add two variable and
store it  into $result*/
    $result=$var1 - $var2;   /*subtract first variable by
second and store it into $result*/
    $result=$var1 / $var2;   /*divide first variable by
second and store it into $result*/
    $result=$var1            /*assign $result the value of
$var1*/
?>


condition in php
<?php
   $var1=10;
   if($var1==10) 
       echo "var1 is equal to 10";
   else 
       echo "var1 is not equal to 10";
?>
some thing to remember
== /*for comparision of value if mathamatical value's are equal conditon is true
if mathamatical value's are not equal conditon is false

$var!=checkvalue /*$var value is not equals to checkvalue*/

!$varname means $varname==0

$var=>checkvalue /*$var value is equal or greater than checkvalue*/

$var=
now we had got a little theoretical knowledge,time to apply it ; )
  1. you need a server for viewing a php file
  2. for windows user goto wamp server for windows and for linux user please install lamp for your distro and replace c:/wamp/www/ with /var/www/
  3. download and install it
  4. run wamp server and a small semicircle will appear in your right of windows task bar
  5. usually it install it in c: drive as per convention im taking c: drive
  6. open notepad and copy the below text in it and save it to c:/wamp/www/first.php
    for linux user save the file with root permission or it will not let you save
  7. open you browser and type http://localhost/first.php
  8. and you will see your first php program
<html>
<head>
<title>my first php program</title>
</head>
<body>
<?php
      echo "hello world";
      $sum=1+5;
      echo "adding 1+5=$sum"; /*try replacing the double
quote with single quote and see what happens*/
?>
</body>
</html>
that's all folks your first php programs you
please do leave comment's and please don't hesitate to criticize the content if necessary because
"when we kick a football it moves forward"

now you are ready for the next level.

Labels: , , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home