Communications and Networking:Server-side scripting

From Wikibooks, open books for an open world
Jump to: navigation, search

UNIT 3 - ⇑ Communication and Networking ⇑

← Wireless Networks Server-side scripting Internet Security →

Server-side scripting - The basis of dynamic web page content.


Common Gateway Interface (CGI)[edit]

  Blank.svg ---
Down arrow Hexagonal Icon.svg
Left arrow Hexagonal Icon.svg Right arrow Hexagonal Icon.svg Address http://www.example.org/index.html Rosette Hexagonal Icon.svg Book Hexagonal Icon.svg Paper Hexagonal Icon.svg

Welcome

To this webpage


  Blank.svg ---
Down arrow Hexagonal Icon.svg
Left arrow Hexagonal Icon.svg Right arrow Hexagonal Icon.svg Address http://www.example.org/index.html?lang=fr Rosette Hexagonal Icon.svg Book Hexagonal Icon.svg Paper Hexagonal Icon.svg

Bonjour

To this webpage


CPT-internet-CGI.svg
Extension: AJAX

AJAX is an acronym for Asynchronous JavaScript and XML, technologies that can be used on the client-side to create asynchronous web applications. With AJAX, web applications can send data to, and retrieve data from, a server asynchronously (in the background) without interfering with the display and behavior of the existing page. Examples of this might be receiving a new email in your web based mail client without having to refresh the page manually, another example is a breaking news article appearing on a news site without you having to refresh the page. Web 2.0 sites make heavy use of AJAX and data is usually retrieved using the XMLHttpRequest API.

Web 2.0 Map.svg

You can learn more about how AJAX works over at w3schools.

Server-side scripts[edit]

A server-side script can make a webpage dynamic. This means that content is generated when the web browser request is received rather than being static and displaying one screen. The webpage can handle requests such as HTTP requests to do something useful with data that a user has inputted.

HTML[edit]

HTML stands for HyperText Markup Language and is a way of displaying a webpage on a browser by using tags to create objects on the screen. The objects on the webpage can be styled using Cascading Style Sheets or adding styles directly to a tag. The most recent version of HTML is HTML5 which is coupled with CSS3. The difference with HTML5 and HTML4 is that HTML5 has more tags that can create more complex objects like date pickers and placeholder text in input boxes. However not all web browsers support HTML5 and those that do, they don't support all of the new elements that are in HTML5. What is about HTML5 is that when you are declaring <!DOCTYPE> for the webpage to tell the web browser what you are using, you only have to write <!DOCTYPE html> and only that rather than adding URLs to framesets in w3 or declaring PUBLIC. HTML5 has made life easier for web designers.

<html>
  <head>
    What goes on behind the scenes...
  </head>
  <body>
    What the web browser displays...
  </body>
</html>

PHP[edit]

PHP is a recursive acronym that stands for PHP Hypertext Preprocessor. It is a server-script that is ran each time the page is reloaded and can handle MySQL and is how most websites are created. PHP can output text to a webpage. PHP interpreters are ran on the web server so all requests are handled by the web server and then outputted as text that a web browser can display. Variables are created using the $ symbol.

Post Request[edit]

The post request is a HTTP request where an HTML form can 'post' data to a page that can process the data using the server-side scripts such as PHP or JavaScript.

<?php
  if($_POST["submitForm"]){
    $firstName = $_POST["firstname"];
    echo $firstName;
  }
?>
<form method="post" action="page.php">
  First Name: <input type="text" name="firstname" placeholder="First Name">
  <input type="submit" name="submitForm" value="Submit">
</form>

Database Management Systems (DBMS)[edit]

'Database Management Systems (DBMS)' are systems that can be accessed by web server extensions. A well known DBMS is a MySQL database.

How to Connect to a DBMS using Server-side Scripting[edit]

  1. Connect to the hosting server
  2. Select a database
  3. Perform a query for that database
  4. Handle the data in the way that is required
  5. Disconnect from the database

PHP example of MySQL Connection[edit]

$connect = mysqli_connect("localhost", "username", "password", "databasename");