PHP: Difference between revisions

1,241 bytes added ,  15:13, 23 May 2020
m
Line 33: Line 33:


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).
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).
=== Advantages of PHP scripts ===
PHP is relatively easy to learn, because it can be used either in a very simple way, or when you learn more in a very sophisticated way.  One advantage of PHP scripts is because they are processed by the web server nobody can steal your script unless you use some functionality like that [https://cumulus.hosiene.co.uk/viewtopic.php?f=14&t=16425&p=126065 described here]. If you are writing a set of web pages, you can make your web suite very much easier to maintain by not putting every instruction into one script, you can use syntax like 'require' or 'include' to effectively bring in common code from other scripts. These other scripts might contain standard functions (like connecting to a database, reading from a database and calculating highest or lowest) or they might contain a standard navigation header that you want for all your web pages (with ability to identify which script is the current one, which CSS files to attach, and so on). But the basic reason for using a script is that it can make a web page look different depending on any data you choose (time of day, current season, whether it is raining, how hot it is) or it can display different content depending on particular values.


=== Learning More about PHP ===
=== Learning More about PHP ===
Line 46: Line 51:


One possible advantage of this type of script is that by default the script cannot be seen (unless the developer has added some code ([https://cumulus.hosiene.co.uk/viewtopic.php?f=14&t=16425 see this forum topic]) 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).
One possible advantage of this type of script is that by default the script cannot be seen (unless the developer has added some code ([https://cumulus.hosiene.co.uk/viewtopic.php?f=14&t=16425 see this forum topic]) 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).


=== Using PHP in Cumulus templates ===
=== Using PHP in Cumulus templates ===
5,838

edits