PHP: Difference between revisions

From Cumulus Wiki
Jump to navigationJump to search
1,477 bytes added ,  23 April 2015
m
(→‎Using PHP Hypertext Pre-processor: rewrite now on separate page)
= Using PHP Hypertext Pre-processor =
 
Original material by DAJ, but moved to this new page; on a former web-site he used PHP to generate his page, JavaScript to update his page frequently making use of information gathered using AJAX method and the jQuery library of JavaScript code to actually make his script browser independent - see [http://sandaysoft.com/forum/viewtopic.php?f=14&t=5306 support forum].
Many web servers support the PHP scripting language, this means that the web server will parse the contents and obey all the script instructions to generate a pure HTML page that it forwards to a user agent (e.g. browser). The advantage of this type of script is that by default the script cannot be seen (unless the developer has added some code allowing a query-string to be added to the url asking for some or all of the PHP source to be shown to the browser). This makes for a more secure script, because it only runs on the web site server. For instance if information is read from a database or in another way involves a password of some kind, all that code can be hidden, the end-user then has no way to modify the script to get information that should not be seen by others. A disadvantage is that it can be more complicated to update information on a page, requiring the whole page to be regenerated. (Consequently, a mix of scripts may be used with updating by AJAX or JSON, added to the PHP that generates the basic page. That is beyond the scope of this article).
 
Update by [[User:Sfws|Sfws]] ([[User talk:Sfws|talk]]) 17:18, 22 April 2015 (PDT) based on material formerly on Customised templates page.
 
Many web servers support the PHP scripting language, this means that the web server will parse the contents and obey all the script instructions to generate a pure HTML page that it forwards to a user agent (e.g. browser).
 
=== More about PHP ===
 
PHP regularly issues new versions, with major and minor upgrades. You need to ensure that your development server and your production server use the same version, or that you only use features that are common to both versions. If somebody else runs your web server, you need to track what PHP version they use. But since the PHP parser creates a HTML page to pass to each user, it does not matter what any user has on their device.
 
There are volumes of information available on writing PHP scripts, both in your local bookshop, or library, and on the web. Some of these books cover a database query language and maybe running a web server as well as PHP. However, below is a basic introduction to understanding and writing your own PHP to generate your web-page. This Wiki article cannot teach you PHP because it includes a very large number of functions, nor can I tell you if your web server supports PHP, but the examples below give a brief hint of how PHP could be used and should help you to get started.
*Easy lessons on [http://www.w3schools.com/php/ W3 school]
*Reference tutorial on [http://php.net/manual/en/tutorial.php Getting Started] (php.net).
 
 
However, below is a basic introduction to understanding and writing your own PHP to generate your web-page. This Wiki article cannot teach you PHP because it includes a very large number of functions, nor can I tell you if your web server supports PHP, but the examples below give a brief hint of how PHP could be used and should help you to get started.
 
Many web servers support the PHP scripting language, this means that the web server will parse the contents and obey all the script instructions to generate a pure HTML page that it forwards to a user agent (e.g. browser). The advantage of this type of script is that by default the script cannot be seen (unless the developer has added some code allowing a query-string to be added to the url asking for some or all of the PHP source to be shown to the browser). This makes for a more secure script, because it only runs on the web site server. For instance if information is read from a database or in another way involves a password of some kind, all that code can be hidden, the end-user then has no way to modify the script to get information that should not be seen by others. A disadvantage is that it can be more complicated to update information on a page, requiring the whole page to be regenerated. (Consequently, a mix of scripts may be used with updating by AJAX or JSON, added to the PHP that generates the basic page. That is beyond the scope of this article).
 
==== What about Ajax? ====
 
Ajax is, in essence, a concept not a new language. It's basically JavaScript being used to request information, and it works in the background while you are viewing a page on the browser.
 
==== When to use JS (Javascript) or PHP ? ====
 
*Using PHP is much faster (usually); as all the work, of deciding what to include on the web page, is done on the web-server (which should be fast) and only the resulting HTML is sent to the browser.
*JavaScript is slower as the initial page, then all the JS code, is sent to the browser; then code is executed on the PC, and then the page is updated.
*A user may have JS disabled, so you might need to consider how your page will work without it (see above).
*If you do not have PHP on your web-server you need to use JS!
 
== Using PHP in Cumulus templates ==
5,838

edits

Navigation menu