1) PHP – Personal Home Page Scripting Language 2) JavaScript
The transition from static webpages to dynamic webpages means moving from plain webpages to web applications.
In a pill, how the web works? 1)There are two entities: a client (browser) and a server. 2)Traditionally, the client sends some information to the server at a specific URL, requesting a response in a form of an HTML file. 3)The server receives the request, processes it, and sends the HTML file back to the client. 4)The client receives the file and based on its HTML contents renders the webpage and displays it.
What happens when the request to the server is for execution of a CGI application? 1)There are two entities: a client (browser) and a server (with a CGI application). 2)The client sends a request for execution to the server at a specific URL, requesting a response as usual in a form of an HTML file. 3)The server receives the request, processes it by running a CGI application (a script, a C/C++ program, etc.), whose result is an HTML text, and sends the HTML text back to the client. 4)The client receives the response and based on its HTML content renders & displays the webpage.
PHP helps doing the same thing as a CGI: 1)There are two entities: a client (browser) and a server (with a PHP processor engine). 2)The client sends a request for execution to the server at a specific URL, requesting a response as usual in a form of an HTML file. 3)The server receives the request, passes it to the PHP engine, which runs a corresponding script and delivers the results as an HTML text to the server, which in turn passes it back to the client. 4)The client receives the response and based on its HTML content renders & displays the webpage.
PHP Hypertext Preprocessor (Personal Home Pages) A scripting language that offers unified approach to designing dynamic webpages: - it is free (open source) - it is fast in execution and easy to learn - it is universally portable to multiple platforms.
PHP code is embedded in the HTML code. A special tag, usually “ <?PHP ”: is recognized as marking the beginning of PHP code. Symbols “ /* ” and “ */ ” are C-style comments Symbols “ ?> ” mark end of PHP tag
PHP is nearly a typeless language: data types of variables are not declared beforehand, but determined when a variable is assigned a value data type of a variable can change when variable receives a different value integer, double, string, array, object, boolean are the data types used
Variable’s name in PHP must start with a dollar sign $, for example: $var Expression is a valid combination of variables and operators, for example: $var = $var Instruction (more correctly, a statement) is any syntactically valid entity ending with a semicolon, for example: $var = $var;
PHP code can be embedded in HTML directly, for example: This is <?php echo date('l, F dS Y.'); ?>
PHP code stored in a file can be also invoked from HTML, for example: <FORM ACTION="welcome1.php" method="post"> First Name: <INPUT TYPE="text" name="firstname" /> Last Name: <INPUT TYPE="text" name="lastname" />
PHP file welcome1.php would include the code to receive values from the form: <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; echo "Welcome to my website, $firstname $lastname!"; ?>
The typical use of PHP is with a database: - connecting to a database - performing queries - processing the results of a query - updating database entries - logging out and exiting
1) PHP – Personal Home Page Scripting Language 2) JavaScript
While PHP scripts allow interaction, they execute at the server site, which creates network traffic, so the need exists for running scripts on the client (browser) site. Thus JavaScript was created!
JavaScript has typical syntax of high-level languages, but does not require type declaration for variables. Their data types are determined automatically when a variable is assigned value.
JavaScript allows control of: the content of webpages the browser itself, and the HTML forms on the page.
In a pill, how it all works in JavaScript? JavaScript code is embedded in the HTML code:...JavaScript code goes here...
The most interesting feature of Javascript is event handling, which is an asychronous program control. Normally a program executes statements sequentially, one after another, perhaps branching, but still in a predetermined sequence.
This sequence may change abruptly when a certain event occurs, which needs immediate attention. Such situations happen with interrupts at the hardware level, and with JAVA and C++ exceptions at the software (programming language) level. To deal with it, one needs to develop an interrupt of exception handler.
In JavaScript, these abrupt events are some action requests triggered by the client. One can program a response to such events using event handlers, that is, code segments that react appropriately, depending on the kind of action desired by the client.
Sample events handled in JavaScript: onClick onMouseOver onKeyDown onLoad onSelect onAbort and many others.
Handling a sample event via a form (under the assumption that the event handler has been defined separately): <INPUT TYPE = ”button” VALUE = ”Click here” onClick=”alert(You clicked on me!”
JavaScript does not have: graphics capabilities file I/O networking multithreading.
Final Remarks Microsoft’s response to the emergence of JavaScript was VBScript (Visual Basic Scripting Edition) JavaScript can also run on the server side, but is much less popular, because of PHP & perl