{"id":435,"date":"2017-02-13T18:45:21","date_gmt":"2017-02-13T18:45:21","guid":{"rendered":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/?page_id=435"},"modified":"2017-03-17T14:30:44","modified_gmt":"2017-03-17T14:30:44","slug":"chapter-4-adding-a-dynamic-layer-introducing-the-php-programming-language","status":"publish","type":"page","link":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/chapter-4-adding-a-dynamic-layer-introducing-the-php-programming-language\/","title":{"rendered":"Chapter 4: Adding a dynamic layer &#8211; Introducing the PHP programming language"},"content":{"rendered":"<h2>Static vs dynamic web pages<\/h2>\n<p>For how powerful HTML and CSS are, they allow us to build gorgeous web pages and web sites and indeed are the basis for any web page or website we build, they do have a precise limit in the fact that all we can do with them is to build &#8220;static&#8221; pages. We can build\/write the code for several static pages, link the pages to one another, and there we have a web site. A static web site.<\/p>\n<p>The following figure illustrates the main difference between a static and a dynamic web site.<\/p>\n<p>A <strong>static web page<\/strong> is a text file, with contents marked up with HTML and eventually styled by CSS, which sits somewhere in the web server file system, waiting to be sent to a browser when\u00a0a user visits the URL that points to it. Therefore, this text file, also known as the &#8220;source&#8221; of the web page, pre-exists on the web server and is sent to the user&#8217;s browser, as it is, on demand.<\/p>\n<p>In contrast, a <strong>dynamic web page<\/strong> contains at least some elements that rather than being already present in the source file, are added to it &#8220;on the fly&#8221; by the web server, when the user visits it&#8217;s URL.<\/p>\n<figure id=\"attachment_542\" aria-describedby=\"caption-attachment-542\" style=\"width: 2678px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/02\/static_vs_dynamic_web_pages-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/02\/static_vs_dynamic_web_pages-1.png\" alt=\"Static versus dynamic web pages\" width=\"2678\" height=\"1966\" class=\"size-full wp-image-542\" srcset=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/02\/static_vs_dynamic_web_pages-1.png 2678w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/02\/static_vs_dynamic_web_pages-1-300x220.png 300w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/02\/static_vs_dynamic_web_pages-1-768x564.png 768w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/02\/static_vs_dynamic_web_pages-1-1024x752.png 1024w, http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-content\/uploads\/2017\/02\/static_vs_dynamic_web_pages-1-1200x881.png 1200w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption id=\"caption-attachment-542\" class=\"wp-caption-text\">Figure 4-1: Static versus dynamic web pages<\/figcaption><\/figure>\n<p>This concept maybe not immediately easy to grasp, but trust that it will become clear after going through <a href=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/chapter-4-adding-a-dynamic-layer-introducing-the-php-programming-language\/getting-started-with-dynamic-web-pages-with-php-a-simple-yet-useful-example\/\">the example in the next page<\/a>.<\/p>\n<p>Whether the page is static or dynamic, at the end of the day the result for the end user is the same, the user experience does not change, and visiting an URL with a browser will have, as a final result, that the web server sends a (static) text file with the HTML source to the browser, which than takes care of graphically rendering this as a web page that the user can see in the browser window. The difference lies in how this text file with the HTML source code is generated by the web server. In static pages, the text file is already there, in dynamic page is has to be somehow created\/assembled, before it is sent over.<\/p>\n<h2>Programming languages<\/h2>\n<p>In order to have the web server create or assemble a dynamic page, we do need a programming language of some sort. There are several programming languages that are fit to execute such a task. To cite just a few among the most popular, Perl, Python and Ruby would all be suitable for the job. Those languages normally execute as &#8220;console applications&#8221;, that is we can run applications written in those languages in a computer shell. In order to be usable in a web framework however,\u00a0we need to resort to <a href=\"https:\/\/en.wikipedia.org\/wiki\/Common_Gateway_Interface\">CGI (Common Gateway Interface)<\/a>, a common protocol that allows us to run console applications in an environment controlled by a web server, in short, as web applications.<\/p>\n<p>Depending on the task we are willing to achieve, or the application we are building, indeed one of those languages could be the best choice. For instance, in the last years Python has become one of the languages of choice for the development of bioinformatics applications. It is extremely powerful, complete, it\u00a0allows to process data very fast and has a number of libraries available dedicated to bioinformatics.<\/p>\n<h2>PHP<\/h2>\n<p>However, for the purpose of this course, mainly targeted at\u00a0beginners in the field of development and programming, we will select a different language, that has the advantage to be natively born for building web applications and managing dynamic web pages, therefore allowing to entirely bypass the CGI layer and the associated learning curve. This language, called <a href=\"http:\/\/php.net\/\">PHP<\/a> (<a href=\"http:\/\/php.net\/manual\/en\/intro-whatis.php\">recursive acronym for PHP: Hypertext Preprocessor<\/a>), has seen a continuous development in the last years and is available, at the time of this writing, as version 7 (PHP 7). See <a href=\"https:\/\/en.wikipedia.org\/wiki\/PHP\">here<\/a> for an history of the language development.<\/p>\n<p>While in his very early times PHP had a reputation for being somewhat slow in rendering web pages, this is not true anymore and several extremely popular web frameworks\/Content Management Systems (CMS) are based on PHP. Notably, WordPress, that is used on more than 25% of all websites on the Internet (<a href=\"https:\/\/w3techs.com\/technologies\/details\/cm-wordpress\/all\/all\">source<\/a>) is written in PHP.<\/p>\n<p>Here are a few assets of PHP, not necessarily in order of importance:<\/p>\n<ul>\n<li>natively designed to build web applications, born for the web, no CGI<\/li>\n<li>full featured<\/li>\n<li>supports Object Oriented Programming<\/li>\n<li>can be used as a &#8220;general purpose&#8221; programming language (not limited to web applications)<\/li>\n<li>soft learning curve, easier to learn with respect to other languages<\/li>\n<li>used in several popular web development frameworks such as WordPress<\/li>\n<li>generally available on every web server<\/li>\n<\/ul>\n<p>For all these reasons, it is the programming language of choice for this course on web development for bioinformatics.<\/p>\n<p>Let us start with a <a href=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/chapter-4-adding-a-dynamic-layer-introducing-the-php-programming-language\/dynamic-web-pages-with-php-a-simple-yet-useful-example\/\">quite simple example<\/a> of how to use PHP to serve a webpage that does not pre-exist on the server as a static text page. Although simple, this example provides a valuable insight on how to greatly simplify the management of a website comprising several pages.<\/p>\n<div style=\"padding:10px;border:1px dashed darkgrey;font-size:0.8em;color:darkgrey\">\n<strong>Image credits:<\/strong><br \/>\nServer icon: https:\/\/www.iconfinder.com\/icons\/308002\/server_icon<br \/>\nFirefox browser icon: https:\/\/www.iconfinder.com\/icons\/10624\/firefox_mozilla_icon<br \/>\nText file icon: https:\/\/www.iconfinder.com\/icons\/46823\/notes_icon\n<\/div>\n<div class=\"google-ad\">\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<!-- bioinfo web dev 2 --><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:inline-block;width:728px;height:90px\"\n     data-ad-client=\"ca-pub-0159360445983090\"\n     data-ad-slot=\"3442176918\"><\/ins><br \/>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n<\/div>\n<h2>Chapter Sections<\/h2>\n<p>[subpages]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Static vs dynamic web pages For how powerful HTML and CSS are, they allow us to build gorgeous web pages and web sites and indeed are the basis for any web page or website we build, they do have a precise limit in the fact that all we can do with them is to build &hellip; <a href=\"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/chapter-4-adding-a-dynamic-layer-introducing-the-php-programming-language\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Chapter 4: Adding a dynamic layer &#8211; Introducing the PHP programming language&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":4,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-435","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/pages\/435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/comments?post=435"}],"version-history":[{"count":15,"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/pages\/435\/revisions"}],"predecessor-version":[{"id":1444,"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/pages\/435\/revisions\/1444"}],"wp:attachment":[{"href":"http:\/\/www.cellbiol.com\/bioinformatics_web_development\/wp-json\/wp\/v2\/media?parent=435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}