You are on page 1of 28

Sarang Pitale

Asst. Professor Bhilai Institute of Technology,Durg. www.dsarang.com


CreatedBy:Sarang Pitale

Web Applications
An application that is accessed over a network such as the Internet or an intranet. also mean a computer software p application that is hosted in a browser-controlled environment or coded in a browser-supported language (such as JavaScript, combined with a browser-rendered markup language like HTML) and reliant on a common web b li t b browser t to render the application executable.

CreatedBy:SarangPitale

Why Web Applications?


Web applications do not require any complex " ll out" procedure t d l i l "roll t" d to deploy in large organizations. A compatible web browser is all that is needed. Browser applications typically require little li l or no di k space on the client. disk h li They require no upgrade procedure since all new features are implemented on the server and automatically delivered to the y users. Web applications integrate easily into other server-side web procedures, such as e a a d sea c g. email and searching. They also provide cross-platform compatibility in most cases (i.e., Windows, Mac, Linux, etc.) because they operate within a web browser window window.

CreatedBy:SarangPitale

Software Bundles
Software Bundles are Required for q the development of web application. Operating System Programming Language DBMS Application Server
DBMS Ope at g Operating System

Web Application

Application Server

Programming Language

CreatedBy:SarangPitale

LAMP
Linux (operating system) Apache HTTP Server MySQL (d b M SQL (database software) f ) Perl/PHP/Python

WAMP
Microsoft Windows Apache HTTP Server MySQL (database software) Perl/PHP/Python

MAMP
Macintosh Apache HTTP Server MySQL (d t b M SQL (database software) ft ) Perl/PHP/Python

SAMP
Solaris Apache HTTP Server MySQL (database software) M SQL (d b f ) Perl/PHP/Python

FAMP
FreeBSD Apache HTTP Server MySQL (database software) Perl/PHP/Python

XAMPP
X (to be read as "cross", meaning cross-platform) Apache HTTP Server MySQL (d t b M SQL (database software) ft ) Perl/PHP/Python

XAMPPEasy to use apache Distribution


a free and open source cross-platform p p web server solution stack package

X(crossplatform) X( l f )

ApacheHTTPServer

MySQL

PHP/PerlLayouts

CreatedBy:SarangPitale

Client Server Interaction Using LAMP


HTTP Request
(http://www.facebook.com)

HTTP Response

Web Wb Browser

Apache A h MySQL Php


Query Result

Client Server

CreatedBy:SarangPitale

Created By:Sarang Pitale

PHP

5.3.1

PHP was originally created by Rasmus Lerdorf in 1995. General-purpose server-side General purpose server side scripting language originally designed for web development to produce dynamic web pages. PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module which generates the web module, page document. PHP is installed on more than 20 million websites and 1 million web servers. PHP is used as the server-side programming language on 75% of all web servers. Web content management systems written in PHP include Joomla, eZ Publish, WordPress,Drupal and Moodle. All websites created using these tools are written in PHP, including the g , g user-facing portion of Wikipedia, Facebook, and Digg.
CreatedBy:SarangPitale

CreatedBy:SarangPitale

Step-ByStep-By-Step
Write and execute a simple PHP script Create statements and comments, and name variables Use variables to store values Choose b t Ch between PHP data types PHPs d t t Understand the special NULL data type Read GET and POST form input, and store it in variables Perform calculations and comparisons using operators

CreatedBy:SarangPitale

Write and execute a simple PHP script


One of the nicer things about PHP is that, unlike CGI scripts, which require you to write server-side code to output HTML, PHP lets you embed commands i regular HTML pages. d in l These embedded PHP commands are enclosed within special start and end tags, tags which are read by the PHP interpreter when it parses the page.

<?php ... PHP code ... ?>

CreatedBy:SarangPitale

Writing Statements and Comments


<?php Comment styles listed here Single Line Comment Multi Line Comment g // this is a single-line comment # so is this /* and this is a multiline l ili comment */ ?>

CreatedBy:SarangPitale

Use variables to store values


PHP supports a number of different variable types: Booleans, integers, floating point numbers, strings, arrays, objects, resources, and NULLs The language can automatically determine variable type by the context in which it is being used. Every variable has a name which is name, preceded by a dollar ($) symbol, and it must begin with a letter or underscore character, optionally followed by more , , letters, numbers, and underscores. For example, $popeye, $one_day,and $INCOME are all valid PHP variable names, while $123 and $48hrs areinvalid variable names names.
<?php // define variable $answer = 'Elephant'; // print output echo "<h2><i>$answer</i></h2>"; ?> <?php $age = $dob + 15; ?> <?php $today = "Jan 05 2004"; echo "Today is $today"; ?>

CreatedBy:SarangPitale

Choose between PHP s data types PHPs

CreatedBy:SarangPitale

Detecting the Data Type of a Variable


To find out what type a particular variable is, i PHP offers th gettype() f ti ff the tt () function,

<?php //definevariables $auth true; $auth=true; $age=27; $name='Bobby'; $temp=98.6;//returns"string" echogettype($name); h tt ( ) //returns"boolean" echogettype($auth); //returns"integer" g echogettype($age); //returns"double" echogettype($temp); ?>

CreatedBy:SarangPitale

A Note on String Values


String values enclosed in double quotes are automatically parsed for variable names; if variable names are found, they are automatically replaced with the appropriate variable value. ih h i i bl l Note that if your string contains y g quotes, carriage returns, or backslashes, its necessary to escape these special characters with a backslash.
<?php $identity = 'James Bond'; y $car = 'BMW'; // this would contain the string "James Bond drives a BMW" $sentence = "$identity drives a $car"; $identity $car ; // this would contain the string "$identity drives a $car" $sentence = '$identity drives a $car'; ?> <?php // will cause an error due to mismatched quotes $statement = 'It's hot outside'; // will be fine $statement = 'It\'s h t outside'; $t t t 'It\' hot t id ' ?>
CreatedBy:SarangPitale

A Note on NULLValues NULL Values


PHP 4.x introduced a new data type for empty variables, called NULL. The NULL d h data type i special: i is i l it means that a variable has no value. A NULL is typically seen when a variable is initialized but not yet assigned a value, or when a variable has been de-initialized with the unset() f ti t() function.
<?php // check type of uninitialized variable // returns NULL echo gettype($me); // assign a value $me = 'David'; // check type again // returns STRING echo gettype($me); // deinitialize variable unset($me); // check type again // returns NULL echo gettype($me); ?>

CreatedBy:SarangPitale

Using Operators

If variables are the building blocks of a programming language, operators are the glue that let you do something useful with them.

CreatedBy:SarangPitale

Accessing Variables Passed from the Browser


<html> <head></head> <body> <form action="message.php" method="post"> Enter your message: <input type="text" name="msg" size="30"> <input type="submit" value="Send"> </form> </body> </html>

<?php // retrieve form data in a variable $input = $ $ $_POST['msg']; // print it echo "You said: <i>$input</i>"; ? ?>

CreatedBy:SarangPitale

Passing arrays
<form action=mypage. hpp method=POST> <select name=j_names[] size=4 multiple> <option value=2>John <option value=3>Jay <option value=4>Jackie p <option value=5>Jordan <option value=6>Julia </select> <input type=submit value=submit> </form>

if (is_array($ POST[j names])) ( y($_ [ j_ ])) { echo <b>the select values are:<br> <br>; foreach ($_POST[j_names] as $value) { echo $value . <br>\n; } }

CreatedBy:SarangPitale

PHP Date -Format the Date


The first parameter in the date() function specifies how to format the date/time. It uses letters to represent date and time formats. Here are some of the l f h letters that can b used: h be d d - The day of the month (01-31) m -The current month, as a number , (01-12) Y - The current year in four digits Other characters, like / , ".", or "-" characters like"/" can also be inserted between the letters to add additional formatting:
The output of the code above could be something like this: 2006/07/1 1 2006.07.1 2006 07 1 1 2006-07date("Y/m/d"); ( ); echo"<br />"; echo date("Y.m.d"); echo "<br />"; Echo date("Y-m-d"); ?> date("Y m d");

CreatedBy:SarangPitale

Sessions
A PHP session variable is used to store information about, or change settings for a usersession. Sessionvariables hold information about one single user, and are user available to all pages inone application.
<?php unset($_SESSION['views']); ?> <?php session_destroy(); ?> <?php session_start(); // store session data $_SESSION['views']=1; ?> <html><body> h l b d <?php //retrieve session data echo "Pageviews=". $_SESSION['views']; ?> </body> </html> y <?php session_start(); (); if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+ 1; else $_SESSION['views']=1; echo "Views=.$_SESSION['views']; ?>

CreatedBy:SarangPitale

PHP Sending E-mails E<?php $to = "someone@example.com"; $subject = "Test mail"; $message = "Hello! This is a simple email "; Hello! email. ; $from = "someonelse@example.com"; $headers= "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?>

The PHP mail() function is used to send emails from inside a script. d il f i id i

CreatedBy:SarangPitale

Connecting To Database
The free MySQL Database is very often used <?php $con = with PHP. PHP mysql_connect( localhost peter abc123 ); mysql connect("localhost","peter","abc123"); if(!$con) Before you can access and work with data in { die('Could not connect: ' . mysql_error()); a database, you must create a connection to } the database. database // Create database C d b if (mysql_query("CREATE DATABASE In PHP, this is done with the mysql_connect() my_db",$con)) function. { echo "Database created"; } ; else { echo "Error creating database: " . The connection will be closed as soon as the mysql_error(); } script ends. To close the connection before, use // Create table in my_db database themysql_close() function. y q_ () mysql_select_db("my_db", $con); l l t db(" db" $ ) $sql = "CREATE TABLE Person ( FirstName varchar(15), LastName ( ) g )"; varchar(15), Age int ) mysql_query($sql,$con); mysql_close($con); ?>
Created By:Sarang Pitale

Display the Result in an HTMLTable HTML Table


<?php $con = mysql_connect("localhost","peter","abc123"); if(!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM person"); echo " bl b d '1' <tr> h "<table border='1'> <th>Firstname</th> <th>Lastname</th> </tr>"; while($row = mysql_fetch_array($result)) yq y($ )) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "</tr>"; } echo "</t bl >" h "</table>"; mysql_close($con); ?>
CreatedBy:SarangPitale

The following example selects the same data as the example above, but will display the data in an HTML table

www.dsarang.com www dsarang com Email: mail@dsarang.com


Created By:Sarang Pitale

You might also like