This is HTML - IFIC

obtainablerabbiΔιαχείριση Δεδομένων

31 Ιαν 2013 (πριν από 4 χρόνια και 6 μήνες)

136 εμφανίσεις

PHP and a WEB server to
access ANTARES DB

E. Carmona

What is PHP?


“PHP is a widely
-
used general
-
purpose scripting language that is
especially suited for Web development and can be embedded into
HTML”



Widely used
: Millions of dynamic web pages in the world use this language.
Thousands of resources available in Internet



General purpose
: Hundreds of libraries and functions covering very different
subjects like database access, network protocols, cryptography, XML, …



Script language
: PHP does not need to be compiled into an executable. It is
byte
-
compiled/interpreted by the PHP interpreter. People familiar with PERL
will find many coincidences with PHP (very similar syntax)



Web development
: Ideal to develop WEB applications but can be used in
any system like any script language



Embedded into HTML
: Naturally integrated into web pages

How it works?


Request of a web page with PHP extension to a WEB server:

1. 1 Requests a .php
web page to the server

1.2 The server serves the request
and since it is a PHP page asks
the PHP engine to process the
PHP code in the requested page

1.3 Executes the PHP
code. The result is a static
WEB page (HTML)

2.1 The result of the
execution is sent back to
the WEB server. No code is
sent back, only the result of
the execution

2.2 A static web page is the
result of executing the
code. This is sent to the
client. Only HTML is sent to
the browser

2.3 The static web page
(HTML only) is rendered in
the client browser

Client (browser)

WEB server

PHP engine

1

1

2

2

WEB server with PHP support


No code travels through Internet, only the result of the execution (HTML)


The client only represents the information, the execution takes place in the server

How it works?

PHP source program

Static HTML result

In user browser

<HTML>

<HEAD></HEAD>

<BODY>

My test program <BR>

<?php

$a = 1;

$b = 2;

$sum = $a + $b;

echo “Result: $sum”;

?>

</BODY>

</HTML>

<HTML>

<HEAD></HEAD>

<BODY>

My test program <BR>

Result: 3

</BODY>

</HTML>

My test program

Result: 3

PHP code embedded in the HTML
web page. The PHP tags (<?php and
?>) limit the PHP block

The result of the execution is
the HTML page + the output of
the PHP block

The resulting static HTML
page is sent to the browser
and displayed there

An example program

A sample program using PHP and its output






<!


One first example
--
>



<html>



<head>




<title> Example of PHP </title>



</head>




<body>



This is HTML



<BR><BR>




<?php



echo “This is PHP <BR>”;



for ($i=0;$i<10;$i++)



{




echo “Line “ . $i . “<BR>”;



}



?>




</body>



</html>

Arrives to the browser:

<!


One first example
--
>

<html>

<head>


<title> Example of PHP </title>

</head>


<body>

This is HTML

<BR><BR>


This is PHP <BR>

Line 0<BR>

Line 1<BR>

Line 2<BR>

Line 3<BR>

Line 4<BR>

Line 5<BR>

Line 6<BR>

Line 7<BR>

Line 8<BR>

Line 9<BR>



</body>

</html>

Some concerns…


When developing ANY WEB application security is the main issue



The WEB server must be very well configured



Your code can become a security hole. Any bug in the code, any
unexpected behaviour or any incorrect configuration setting can be used
by a malicious user to break into the system, render it useless or steal,
corrupt or delete your data



Also take into account that all PHP operations take place in the server.
Heavy applications should be avoided unless you have a powerful
server or you can balance the charge among different servers



PHP and DataBase access


PHP works with many different DataBases (DDBB)


Specific functions for: Microsoft SQL server, mSQL, MySQL, Oracle,
PostgreSQL, SQLite, Sybase, ODBC, DBD, DBX…


Very popular in the WWW the combination PHP + MySQL


The WEB server and the DB server do not need to be in the same machine


Security: DB passwords are used only by the PHP program, access to the DB
can be limited to the WEB server machine

Client (browser)

WEB server

PHP engine

1

1

2

2

WEB server with PHP support

DB Manager

1

2

DataBase

server

1. Database requests are sent from the PHP
engine to the DB server



2. The results are sent to the PHP engine where
they are processed

PHP + Oracle


Oracle is supported by PHP, but usually is not available in the
distributed binaries and you need to compile your PHP binary with
Oracle support


Access Oracle 10, Oracle 9, Oracle 8 and Oracle 7 databases using the
Oracle Call Interface (OCI)


Some functions for Oracle DB access are only supported by PHP 5, but
the basic functionality is supported in PHP 4


To build PHP with Oracle support you will need the Oracle client
libraries. Download from:

http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html



RPMs of PHP 4 compiled with Oracle support for RH7.3 and SL3
available at:

http://
evalu71.ific.uv.es/
antares/rpms/



Still need to install the Oracle client libraries and to properly set your
LD_LIBRARY_PATH variable

An example application


A web page with a small form to introduce the search criteria for
ANTARES runs. Available at




http://evalu71.ific.uv.es/antares/runs/



The operation of the program is simple. The common operation in
thousands of web pages:

1.
Data from the form is used to build a string containing the SQL query to find
runs matching the selection criteria


2.
The obtained query is sent to the ANTARES DB server


3.
The results from the query are returned from the DB server to the PHP
engine


4.
The results are used to build a table (in HTML) showing the runs matching
the search criteria


However, NOT everything is done using only PHP. Javascript has been
used to improve the interface with the user


PHP can be combined with Javascript (Remember: Javascript is executed
in the browser, PHP in the server)

An example application

Form part


The filled fields
are used to
build the query
that will be
executed
when the
submit button
is pressed

Results part


The results of
the previously
executed
search are
shown

Summary


WEB server + PHP + DB server

are very powerful tools to share
information through Internet



PHP is a very easy
-
to
-
learn script language that can be embedded into
HTML pages to produce dynamic WEB pages



A lot of potential to provide access to the ANTARES DB data without
giving total access to the DB (dangerous)



RPMS of PHP compiled with Oracle support available for RH7.3 and
SL3



An example of a simple PHP application for displaying information of the
ANTARES runs available at:




http://evalu71.ific.uv.es/antares/runs/



Many PHP resources in Internet, in particular look at:





http://www.php.net