Professional Documents
Culture Documents
What is Opensource?
- A source is shared
- A source is modified
- -a source is redistributed after performing some modifications
- A source is allowed to be modified by anyone
What is OSP?
Programming Languages:
PHP
Python
PERL
TCL/TK
Ruby
Zope
Opensource Databases
1. MYSQL- very popular RDBMS (http://www.mysql.com)
2. Postgresql- A popular opensource RDBMS with many
advanced feature(http://www.postgresql.org)
Opensource Webservers
Apache HTTP server for unix and Windows.
PHP compatible with 3 leading webservers Microsoft Internet
Information server and (MIIS)
Netscape Enterprise Server (NES)
ISAPI( Internet server application programming Interface)
Desktop Application:
Open office- An integrated office suite featuring,
wordprocessing, spreadsheet, drawing and presentation
software largely compatable with ms office
(http://www.openoffice.org)
Ximion Evolution: A GUI desktop application for personal email,
calendar and diary having similar look feel with Microsoft
outlook. (http://www.ximion.org)
Mozila- The opensource evolution of the popular netscape web
browser (http://www.mozila.org)
Software Development
GCC (GNU compiler collection/GNU c compiler)- the compiler
for c, c++,fortran, java that comes standard with all the major
OSS operating systems.
( http://gcc.gnu.org)
JBOSS- A popular opensource implementation of J2EE
(http://www.jboss.org)
PERL- A very popular language widely used in scripts to drive
‘live content’ on the www (http://www.perl.org)
PHP- a very popular scripting language for interactive web
development and applications (http://www.php.net)
Python- a popular object oriented scripting language for web
and desktop development (http://www.python.org)
Most of the opensource softwares are released under
GPL(General public License)
Totally 70 opensource licenses are available in OSI website
(http://opensource.org/licenses/alphabetical)
Some of the licenses are,
Academic free license
Adaptive public license
Apache software license
Apple public source license
Boost software license (BSL)
Common public attribution license(CPAL)
IBM public license
MIT license
WWW license
Internet/Intranet services and Applications:
Apache web server- Accounts for over 70% of the webservers
on the internet
BIND name server- Berkeley internet name domain- The
software that provides the DNS (domain name service)
Sendmail (Exchange server)- The most widely used email
transport software on the internet.
Tomcat
JOOMLA
Drupal
Media wiki
IIS
ISAPI
NES
- Opensource S/w operating systems
- Linux
- GNU project
- OPEN BSD
- Free BSD
- Open solaris (unix os from sun microsystems)
OS software sites:
www.fsf.org (free software foundation)
freshmeat.net
sourceforge.net
OSDir.com
Developner.berlieos.de
Individual project sites:
www.apache.org
www.cpan.org
Open source LMS
Moodle
Atutor
Dokeos
OLAT
Mambo
- From security point of view, SSS’s are never visible to the browser
as these scripts are executes on the server and emit HTML
corresponding to users input to the page.
Python (.py)
---------------------------------------------------------------------
History of Open Source
Labs AT&T enforces intellectual property rights and closes the code.
Opensource Companies
IBM- uses and develops apache and linux. Created secure mailer and
other s/w on alphaworks
Active state- develops and sells professional tools for perl, python
and TCL &TK developers.
Merits of Opensource
-They are free (b’coz the greatest thing about OSS is that its free and
available to the general public)
(http://opensource.org)
-They must not restrict other software ( this gives s/w developers
maximum control and flexibility)
Industry consortia,
Companies may license a specification and charge royalties (hefty license fee)
for its use.
Open Standards
Are software specification which are no-proprietory.
Availability
No Royalty
No Discrimination
A copy left is a type of copyright license that allows redistributing the work
(with or without changes) on condition that recipients are also granted these
rights.
Copyleft gives the legal right to everyone to used, edit and redistribute
programs or programs’s code.
PHP- Introduction
Personal homepage
Professional homepage
It is also easy enough to be a beginner's first server side language! (like ASP
and JSP)
PHP files can contain text, HTML tags, CSS, JavaScript, and PHP code
PHP code is executed on the server, and the result is returned to the browser
as plain HTML
Why PHP?
Anyone can visit the php website and to download from the official resource:
www.php.net (PHP is free)
It’s opensource, full featured, clearly designed and cross platform (runs on
different platforms)
PHP can create, open, read, write, delete, and close files on the server
With PHP you are not limited to output HTML. You can output images, PDF
files, and even Flash movies. You can also output any text, such as XHTML and
XML.
Why PHP?
PHP is compatible with almost all servers used today (Apache, IIS, etc.)
PHP 7 is much faster than the previous popular stable release (PHP 5.6)
BASICS of PHP
PHP Tags:
Short_open_tag=on; or enabled;
Asp_tags=enabled;
Php.ini Basics
3. Save this file as phpinfo.php and place it in the document root of your
webserver.
4. Access this file via your web browser and you should see something like…
Php version
OS version information
Paths
Master and local values of configuration option
HTTP headers
Php license
HTML can also be written inside the php section of your web page
<html>
<head>
<head>
?>
</body>
</html>
Comments in php
/* This
Is
Multiline
Comment */
Variables in php
<?php
$text= “ Sumangali”;
echo $text;
?>
<?php
$text= “ Sumangali”;
$text1= “ Associateprofessor”;
echo $text.$text1; // SumangaliAssociateprofessor
?>
$varname=value;
$my_string
$myString
But, in a strongly typed language you have to declare the type of variable.
<?php
$a=”hello”;
?>
<?php
$test=”helloworld”;
$a=”test”; //$a represents variable
echo $$a; // $$a represent a variable with the content of $a
?> o/p: helloworld
Datatypes:
$t=”five”;
echo gettype ($t); //string
echo “<br>”;
$t=true;
echo gettype ($t);//boolean
echo “<br>”;
$t=array(‘apple’, ‘peach’, ‘banana’,9,9.0);
echo gettype ($t);//array
<?php
$undecided=3.14;
settype($undecided, ‘integer’);
echo gettype($undecided);//integer
settype($undecided, ‘bool’);
echo gettype($undecided);//boolean
?>
Eg: $newvar=(datatype)$originalvariable;
<?php
$undecided=3.14;
$holder=(integer)$undecided;
?>
<?php
$a=”opensource”;
print_r(vardump($a);
?>
Type=>string
Value=>opensource
Noofcharacters=>10
Size=>
<?php
$b=3.1;
$c=true;
Var_dump($b,$c);
?>
o/p:
Float(3.1)
Bool(true)
Quotes “ Vs ‘
“- double quoted string any variable names are expanded to their values.
$name=”sona”;
$age=23;
output method: echo and print() is the common method in outputting the
data. echo doesn’t contain parenthesis, since it is a language construct.
define(“YOUR_CONSTANTNAME”, 40);
define(“FOO_BAR”, “something”);
<?php
define(“CONSTANT”, “helloworld”);
$x=10;
You have a file, and in that file you have some HTML and some PHP code.
Assuming a php document with an entension of .php.
2. The web server says “hey! Some one wants a php file, which means this is a
file that needs to be parsed, and sends the request on to the PHP parser.
3. The PHP parser finds the requested file and scans it for PHP code
4. when the PHP parser finds PHP code it executes that code and places the
resulting output (if any) into the place in the file formerly occupied by the
code
4+5=9.
Expression: Combination of operator and operand that can be used
to produce a new value.
Assignment : =
$n=”james”;
$num=9;
“hello”.”web” // helloweb
Combined assignment : += -= *= /=
$x=4
$x+=4//8
$x+=4//12
$x-=3//9
$x=3;
$x=3;
$y=$x++ +3 //6
Comparison :
Takes two operands and returns a Boolean value
<, >, <=, >=, ==, !=, ===, !== ,<> -notequal
$x=4
$x==5 //false
<?php
$x=300;
$y=”300”;
echo “true”;
else
echo “false”;
?> o/p: true (both values are similar but dissimilar datatype, this
== not consider about the datatype)
<?php
$x=300;
$y=”300”;
if($x===$y)
echo “true”;
else
echo “false”;
?> o/p: false (both values are similar but dissimilar datatype)
$x=”300”;
$y=”300”; //true, both values and datatypes are similar.
(condition)?True:False;
<?php
$x=18;
$age=($x<16)?'Eligible':'noteligible';
?>
Logical operator:
! not
$a=2; //integer
Syntax: date(format,timestamp)
Parameter Description
timestamp Optional.
The getdate() function returns an array that contains date and time information for a Unix
timestamp.
The returning array contains ten elements with relevant information needed when formatting a
date string:
[seconds] - seconds
[minutes] - minutes
[hours] - hours
[mday] - day of the month
[wday] - day of the week
[year] - year
[yday] - day of the year
[weekday] - name of the weekday
[month] - name of the month
<?php
?>
Array
[seconds] => 45
[minutes] => 52
[hours] => 14
[mday] => 24
[wday] => 2
[mon] => 1
[year] => 2006
[yday] => 23
<?php
echo("Result with date():<br />");
echo(date("l") . "<br />");
echo(date("l dS \of F Y h:i:s A") . "<br />");
echo("Oct 3,1975 was on a ".date("l", mktime(0,0,0,10,3,1975))."<br />");
echo(date(DATE_RFC822) . "<br />");
echo(date(DATE_ATOM,mktime(0,0,0,10,3,1975)) . "<br /><br />");
echo date(“D”);
echo date(“l”);
?>
Today is
Tue
Tuesday
http://www.php.net/date
Control statements:
2 types:
Switching flow:
If-else- execute set of code when condition is true and not true
<?php
$d=date(“D”);
if($d==”Fri”)
else
?>
$d=date(“D”);
if($d==”Mon”)
?>
If(cond)
//truecode
elseif(cond)
else
// false or others
<?php
$mood=”sad”;
if($mood==”happy”)
elseif($mood==”sad”)
else
?>
switch(exp)
case label1:
//code to be executed exp=label1;
break;
case label2:
break;
case label3:
break;
default:
<?php
$x=3;
switch($x)
case 1:
echo ”No1”;
break;
case 2:
echo ”No2”;
break;
default:
//code to be executed;
<?php
$myvar=0;
while($myvar<10)
echo “hello”;
$myvar++;
?>
do
//code
while(exp);
<?php
$myvar=10;
do
echo “hello”;
$myvar++;
while($myvar<10);
//code
<?php
for($count=1;$count<=12;$count++)
1 times 2 is 2
2 times 2 is 4
..
12 times 2 is 24
for(….)
{
for(…)
//code
1 2 3 4………12
2 24
12 144
1 2 3 4 12
2 4
3 6
4
12 144
foreach($arr as $k=>$v)
//code
}
Write a php script to change the web page background color and
display the current date and time in the webpage, based on the date
function using conditional control statements.
In PHP, you need to declare variables as global and initialize them inside the
function where they are used. A function can contain an unlimited number of
global variables.
Form1.html
<html>
<head>
<body> <h1> this is my first form</h1>
</html>
Action- used to specify the url of the processing script. The browser knows
where to send the form data after it is entered.
Method- indicates a method or protocol sending data to the target action URL
GET/POST
Name=submit- the submit button tells the form to execute the form action
method="get”- this value tells the server how to send the data.
Welcome.php
<?php
echo $_GET["age"];
?>
o/p:
my name is sumangali
my age is 30
$_REQUEST- any variable provided to a script via any user input mechanism.
(post/get). An array of all user inputs including contents.
Arrays in PHP:
Ex:
$user=array(“balu”, “somu”,”ramu”);
echo $user[1];
echo $user[0];
$user[]=”saru”;
print_r($user);
o/p:
Array
Works only on arrays, and will issue an error when you try to use it
on a variable with different data type or uninitialized variable.
Ex.
Numerical index
foreach(array-exp as $value)
stmt
foreach(array-exp as $key=>$value)
stmt
foreach($user as $i)
echo $i;
Ex: stores each element with a numeric id key, and this key is
automatically assigned.
<?php
$name[0]=”banu”;
$name[1]=”pari”;
$name[2]=”sumi”;
?>
2. Associative arrays- array with named keys
Ex:
$character=array(“name”=>”bala”,”occupation”=>”professor”,”age”
=>40, “specialize”=>”DM”);
$character[“occupation”];
o/p: professor
And each element in the sub array can be an array and so on.
$arrbook= array(“comic”=>array(“title”=>”super”,
“author”=>”jerry”,”pub”=>1967), “science”=>
array(“title”=>”newtonlaw”, “author”=>”newton”,”pub”=>1965))
foreach($arrbook as $objkey=>$book)
echo $objkey;
foreach($book as $k=$val)
echo $val;
}
echo “<br>”;
<select name="cars[]" size=”7” multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</form>
Name textbox
Multipleselect.php
<?php
if( !empty($_POST[‘cars’]))
echo “<ul>” ;
foreach($_POST[‘cars’] as $value)
echo <li>$value”;
echo “</ul>” ;
?>
array_sum()
array_pop()
array_push()
array_values()
array_count_values()
unset()- to quickly collapse an array that has some elements unset into
a freshly ordered indexed array with no blank entries.
$arr= array(1,2,3,4,5,6);
unset($arr[3]); //removes 4
unset($arr[5]); //removes 6
print_r($arr);
$arr1=array_values($arr)
print_r($arr1)
Array
[0] => 1
[1] => 2
[2] => 3
[4] => 5
<?php
$greet;
else
$greet= “hi”;
if(isset($greet))
else
>?
isset()- used to check whether the variable has already been set or
not. If set it returns true else false.
However, if you provide the name of the file in the action field, in
case you happened to rename the file, you need to update the action
field as well; or your forms will stop working.
<?php
$n=42;
elseif($_POST[guess]>$n)
elseif($_POST[guess]<$n)
else
{ //must be equivalent
?>
<html>
<body>
</form>
</body>
</html>
isset()- mixed variable usage. Returns, true if the variable contains a value.
Otherwise, false.
Output will be printed within the same page (single form submission)
Using PHP_SELF variable you can write more generic code which can be
used on any page and you do not need to edit the action field.
Consider, you have a file called form-action.php and want to load the
same page after the form is submitted. The usual form code will be:
Here is the combined code, that contains both the form and the PHP
script.
<?php
if(isset($_POST['submit']))
$name = $_POST['name'];
echo "User Has submitted the form and entered this name : <b> $name
</b>";
echo "<br>You can use the following form again to enter a new
name.";
?>
</form>
This PHP code is above the HTML part and will be executed first. The
first line of code is checking if the form is submitted or not. The
name of the submit button is “submit”. When the submit button is
pressed the $_POST['submit'] will be set and the IF condition will
become true. In this case, we are showing the name entered by the user.
Overview of OSS, criteria, standard- copyright and copy left licenses, merits,
oss technologies, open source development cycle…
30 marks
5 to 10m theory
20 to 25m coding
Rules:
1. The name of the function starts with function statement and precedes a set
of parentheses
2. The naming rules for functions are similar to the naming rules for variables,
but without $sign.
3. If your function name requires arguments, you must place comma separated
variable names within the parentheses. These variables will be filled by the
values passed to your function.
4. The function code starts afters the { opening curly braces. Insert the function
code, and the function is finished by a ? closing curly brace.
Even if your function doesn’t require arguments you must nevertheless supply
the parentheses.
Defining function:
}
Eg: Simple function that writes my name when it is called.
<?php
<?php
function writeMyname($fname)
writeMyname(“sumi”) ;
writeMyname(“sumangali”) ;
?>
<?php
writeMyname(“sumi”, “!”) ;
writeMyname(“sumangali”, “…”) ;
?>
<?php
$total=$x+$y;
return $total;
Static
Global
Static:
If you want a local variable not to be deleted after the function is executed,
you can declare it as static.
<?php
function sum()
$ans=1;
echo $ans;
$ans++;
Sum(); 1
Sum(); 1
?> //each time call sum() variable $ans is initialized as fresh and the
result of increment statement is lost. Output is 1 2nd time always 1
<?php
function sum()
Static $ans=1;
$ans++;
}
Sum();
Sum();
?>
Output is 1
Output is 2
Static variable is also local to a function. But it doesn’t lose its value after the
execution over, and can’t be referenced in other functions.
function test1()
Static $x=0;
echo $x;
$x++;
test1();
test1();
test1(); ?>
<?php
function test()
test();
?>
<?php
$b=2;
function test()
$b=$a+$b;
test();
echo $b;
?>
This script will output 3. By declaring $a and $b global within the function. All
references to either variable will refer to the global version.
<?php
$b=2;
function test()
test();
echo $c;
?>
<?php
$life=42;
function meaning_of_life()
global $life;
meaning_of_life();
?>
Any changes made to these variables in the body of the function are local to
that function will not impact the original copy.
<?php
function addfive($num)
$num+=5;
$originalnum=10;
addfive($originalnum);
echo $originalnum;
?>
o/p: 10
The addfive() function accepts a single numeric value and adds 5 to it, but it
returns nothing.
Any changes made to an argument in these cases will change the value of the
original variable.
You can pass a variable by reference of the original variable, and passing that
reference as the calling argument.
<?php
function addfive(&$num)
$num+=5;
$originalnum=10;
addfive($originalnum);
echo $originalnum;
?>
o/p: 15
3. Closing a file – After finishing the working with the file, we need
to close the file.
?>
<?php
if(file_exists(“pathwithinput.dat”))
else
?>
r-read only
w- write only
a- append
x –write only
file opening:
$fp=fopen(“test.txt”, “r”);
$fp=fopen(“test.txt”, “w”);
$fp=fopen(“test.txt”, “a”);