Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Monday, September 23, 2013

PHP-3 : Addition of 2 numbers

Refer this introduction , before doing any PHP program.
PHP Introduction - And some useful points in Programming
  • Open Dreamweaver to write php code , with in the body tag .That is , 
<body>
.......................} php code 
</body> .
and save it (as .php) under the www directory of wamp server.
  • Then click wamp-->localhost to view it in the browser.
=================================================================
<!DOCTYPE html>
<html>
<body>

<?php
$x=5;
$y=6;
$z=$x+$y;
echo $z;
?>

</body>
</html>

Output :
11
========================================================
If we want to display 5, and 6 along with 11, do the program like this:

<!DOCTYPE html>
<html>
<body>

<?php
$x=5;
$y=6;
echo $x ;
echo " +" ;
echo "<br>";
echo $y;
echo "<br>";
echo "..........";
$z=$x+$y;
echo "<br>";
echo $z;
?>

</body>
</html>

Output :
5 +
6
-------
11

Note : 
In PHP these letters (x,y,z etc) are called variables.Variables are "containers" for storing information:
Rules for PHP variables:
  • A variable starts with the $ sign, followed by the name of the variable
  • A variable name must start with a letter or the underscore character
  • A variable name cannot start with a number
  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case sensitive ($y and $Y are two different variables)

Back to HOME & PHP 

PHP-2 : Using color ($)

Refer this introduction , before doing any PHP program.
PHP Introduction - And some useful points in Programming
  • Open Dreamweaver to write php code , with in the body tag .That is , 
<body>
.......................} php code 
</body> .
and save it (as .php) under the www directory of wamp server.
  • Then click wamp-->localhost to view it in the browser.
=================================================================

<!DOCTYPE html>
<html>
<body>

<?php
$color="red";
echo "My car is " . $color . "<br>";
?>  

</body>
</html>

Output :

My car is red

Note :
In PHP , all variables are case-sensitive.
$color="red"...is correct ($COLOR, and $coLOR are wrong.)

Back to HOME & PHP 

PHP-1 : My first PHP

Refer this introduction , before doing any PHP program.
PHP Introduction - And some useful points in Programming
  • Open Dreamweaver to write php code , with in the body tag .That is , 
<body>
.......................} php code 
</body> .
and save it (as .php) under the www directory of wamp server.
  • Then click wamp-->localhost to view it in the browser.
=================================================================

<!DOCTYPE html>
<html>
<body>

<h1>My First PHP Page</h1>

<?php
echo "Hello PHP!";
?>

</body>
</html>

Output : 



Note :

  • "echo" is used to output the text "Hello World!" on a web page (echo is not case-sensitive, that is ,we can write ECHO,EcHo , echo...etc)In PHP there is two basic ways to get output: , ECHO and PRINT . echo can output one or more strings , and can be used with or without parantheses: echo or echo() and print can only output one string, and returns always 1 , also can be used with or without parantheses: print or print() .
  • Always add the <!DOCTYPE> declaration to your HTML documents, so that the browser knows what type of document to expect.That is , when you use a DOCTYPE declarations in your web pages (and many HTML editors likeDreamweaver add them in automatically), you are telling the web browser what version of (X)HTML your web page should be displayed in.
  • A string is a sequence of characters, like "Hello World !".
    A string can be any text inside quotes. You can use single or double quotes:
    That is , we can write "Hello World !" & 'Hello World !'
    ==================================================
Back to HOME & PHP 

PHP Introduction - And some useful points in Programming

Refer WAMP Server & PHP-DATABASE Connection also..
===============================================

How and where to save php files ? To know , click here.

(1) : What is PHP ?
  • PHP files can contain text, HTML, CSS, JavaScript, and PHP code
  • PHP ( Hypertext Preprocessor) is a server scripting language, and is a powerful tool for making dynamic and interactive Web pages quickly.
  • PHP code are executed on the server, and the result is returned to the browser as plain HTML
  • It is a file with the extension .php (dot php) .
Click here to know about HTML Tags .


(2) : Where to type PHP ?
  • Try writing PHP code with this online editor.
  • You can use WAMP server (to view files in localhst)  , and  Dreamweaver. (Click WAMP to install). To know more about WAMP Server, click HERE.
  • There is another and useful IDE called "NetBeans" . You can use this editor for other programming also. Download NetBeans from here for free. (You need JDK or Java Development Kit for installing NetBeans . If you have no Java platform on your system , download from here (which contains JDK+NetBeans ) .

(3) : Set Up PHP on Your Own PC

 if your server does not support PHP, you must:
  • install a web server
  • install PHP
  • install a database, such as MySQL
The official PHP website (PHP.net) has installation instructions for PHP:   Click the official link 
Installation and Configuration


How to check if a PHP function is available on the server?
Write any php code and then you should open the file in a browser and see the result :)

(4) : Basic structure of PHP

A PHP script starts with <?php and ends with ?>:

<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>


<?php
// This is a simple PHP program
echo "Hello World!";
?>

</body>
</html>


Note :

A comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read by someone who is editing the code!

3 types of commands are there in PHP.
  • #
  • //
  • /*  ....... */

(5) : What PHP contains ??

  • PHP files can contain text, HTML, CSS, JavaScript, and PHP code.
Study HTML to know the basic ..

Before proceeding, we should have a little knowledge about CSS and Java Script also. 
These will come in detail on later sessions. 
But , keep this simple points in mind :

(a) : What is JavaScript ?

JavaScript is programming code that can be inserted into HTML pages.
JavaScript is the scripting language of the Web.
All modern HTML pages are using JavaScript to add functionality, validate input, communicate with web servers, and much more.


To insert a JavaScript into an HTML page, use the <script> tag.
The <script> and </script> tells where the JavaScript starts and ends.
The lines between the <script> and </script> contain the JavaScript:

Example : 

<html>

......

        <script>

       alert("My First JavaScript");

        </script>

......

</html> 



(b) : What is CSS (Cascading Style Sheets) ?

An HTML document can be displayed with different styles.
Styles define how to display HTML elements.
In the case of large sites, if we add styles and color in each page , it became large.
That is , Development of large web sites, where fonts and color information were added to every single page, became a long and expensive process. 
To solve this problem , all formatting could be removed from the HTML document, and stored in a separate CSS file. 
CSS defines HOW HTML elements are to be displayed.

Thus, save a lot of work with CSS..Just like JavaScript, CSS also using along with HTML.

A CSS declaration always ends with a semicolon, and declaration groups are surrounded by curly brackets:

Example : 


<html>

.........

        p {color:red;text-align:center;}

..........

</html>


(6) : What is SERVER side scripting & CLIENT side scripting??

?? In the context of web programming, what are the differences between Server-side programming and Client-side programming? Which languages belong to which, and when do you use each of them?

== 3 points you have to note;
  • The Server - This party is responsible for serving pages. 
  • The Client - This party requests pages from the Server, and displays them to the user. On most cases, the client is a web browser. 
  • The User - The user uses the Client in order to surf the web, fill in forms, watch videos online, etc.
(a) Server-side programming :
Server-side programming is writing code that runs on the server, using languages supported by the server (such as Java, ASP,PHP, C#; it is possible to write code that executes on the server-side in JavaScript).
Uses 
  • Process user input. 
  • Display pages. 
  • Structure web applications. 
  • Interact with permanent storage (SQL, files).
(b) Client-side programming

Client-side programming is writing code that will run on the client, and is done in languages that can be executed by the browser, such as JavaScrip,HTML,CSS...etc.
Uses
  • Make interactive webpages. 
  • Make stuff happen dynamically on the web page. 
  • Interact with temporary storage, and local storage (Cookies, localStorage). 
  • Send requests to the server, and retrieve data from it. 
  • Provide a remote service for client-side applications, such as software registration, content delivery, or remote multi-player gaming.
(c) Basic Example
  • The User opens his web browser (the Client). 
  • The User browses to http://google.com. 
  • The Client (on the behalf of the User), sends a request to http://google.com (the Server), for their home page. 
  • The Server then acknowledges the request, and replies the client with some meta-data (calledheaders), followed by the page's source. 
  • The Client then receives the page's source, and renders it into a human viewable website. 
  • The User types http://programming-bca-mca.blogspot.com/ into the search bar, and presses Enter
  • The Client submits that data to the Server. 
  • The Server processes that data, and replies with a page matching the search results. 
  • The Client, once again, renders that page for the User to view.
(7) : What is ASP and PHP difference ??

Both are server side programming . When building web sites, ASP & PHP can interact with Databases and exchange information.
  • ASP (Active Server Pages),is from Microsoft and is used with IIS (Internet Information Server) that runs on Microsoft Servers.It uses MS-SQL. 
  • And PHP ( Hypertext Preprocessor) , runs on various platforms like Linux, Unix, Windows and Solaris servers and it also has an NT server version.It uses MySQL. 
  • ASP is closed source (Closed Source means that the source-code is not available to the public. With Closed Source products you are not allowed to modify, edit, reverse-compile, or otherwise view or change the inner-workings of the product. ) 
  • But PHP is open source (Open Source means that the source-code (the stuff the program/website/driver/etc is made from) is available for anyone to look at and modify for their own purposes). 
  • ASP is a (language-independent) framework, PHP is a language.

(8) : Other doubt you may have...

1 : Difference between Scripting Language & Programming Language.

Usually ,scripting languages are a sub-sets of programming languages.

Scripting Language are languages that allow you to send commands directly to a system that executes these commands. These commands are read line by line and executed. An error is issued when a line cannot be executed for any reasn (wrong syntaxor illegal operation,...). e.g. Python, shell-script, Matlab.

Programming Language are languages that allow you to create a program by writing structured code that is read all at once by the system, checked for errors, and translated into an unreadable format that the machine can then execute. e.g. Java, C/C++, Visual Basic...


(Post if you have any other...)

================================================
===========================================


Back to PHP & WAMP SERVER
Back to HOME