This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:web_development:layout:php [2021/12/13 05:38] mag |
en:web_development:layout:php [2023/08/16 09:33] (current) |
||
---|---|---|---|
Line 233: | Line 233: | ||
==== PHP ==== | ==== PHP ==== | ||
- | * If you want the ability to personalise your site for your customers, (think Amazon recommending particular items based on what you've bought previously or Facebook showing posts from your friends) then | + | * If you want the ability to personalise your site for your customers, (think Amazon recommending particular items based on what you've bought previously or Facebook showing posts from your friends) then you'll need code that runs on a server to access a database and provide that data. |
- | you'll need code that runs on a server to access a database and provide that data. | + | |
* Commonly used server side scripts are Node.js, Net.data, Python and PHP. We'll be using PHP, but you're welcome to try others to see if they' | * Commonly used server side scripts are Node.js, Net.data, Python and PHP. We'll be using PHP, but you're welcome to try others to see if they' | ||
- | * PHP code has many similarity | + | * PHP code has many similarities |
- | * To be processed by the server, all PHP code needs to be in a file with the ' | + | * To be processed by the server, all PHP code needs to be in a file with a ' |
* Your server needs a way to differentiate PHP from the rest of your code so it doesn' | * Your server needs a way to differentiate PHP from the rest of your code so it doesn' | ||
< | < | ||
Line 245: | Line 244: | ||
==== Include ==== | ==== Include ==== | ||
* Before we get into the depths of PHP, let's start with something simple, but very powerful in its time-saving capabilities. | * Before we get into the depths of PHP, let's start with something simple, but very powerful in its time-saving capabilities. | ||
- | * Imagine that you have twenty pages (or more) to manage rather than just the three we have in this folder so far. Now imagine that your boss / client has just asked you to change the company phone number, which appears at the bottom of every page. You'd have to make the change twenty times, then check every single page to make sure you'd done it properly. That's how mistakes | + | * Imagine that you have twenty pages (or more) to manage rather than just the three we have in this folder so far. Now imagine that your boss / client has just asked you to change the company phone number, which appears at the bottom of every page. You'd have to make the change twenty times, then check every single page to make sure you'd done it properly. That's how mistakes |
* Instead, wouldn' | * Instead, wouldn' | ||
* Create a new file called ' | * Create a new file called ' | ||
Line 257: | Line 256: | ||
* At the top of this file add the following code. | * At the top of this file add the following code. | ||
< | < | ||
- | include(" | + | include(" |
- | include(" | + | include(" |
?></ | ?></ | ||
- | * This will add all the code in the files ' | + | * This will add all the code in the files ' |
- | * Now create a file called ' | + | * We could have named the files ' |
+ | * Now create a file called ' | ||
< | < | ||
<html lang=" | <html lang=" | ||
Line 274: | Line 274: | ||
< | < | ||
* Now we'll need to do the same for the the menu and the footer. | * Now we'll need to do the same for the the menu and the footer. | ||
- | * Create files called 'menu.html' and ' | + | * Create files called 'menu.php' and ' |
- | * Add the following code to 'menu.html'. | + | * Add the following code to 'menu.php'. |
< | < | ||
<ul> | <ul> | ||
Line 283: | Line 283: | ||
</ul> | </ul> | ||
</ | </ | ||
- | * Copy the last three lines of ' | + | * Copy the last three lines of ' |
< | < | ||
< | < | ||
Line 289: | Line 289: | ||
</ | </ | ||
</ | </ | ||
- | * We haven' | + | * We haven' |
< | < | ||
- | include(" | + | include(" |
?></ | ?></ | ||
* Save all the files. | * Save all the files. | ||
Line 310: | Line 310: | ||
* Now select all the files and the ' | * Now select all the files and the ' | ||
* To see your page, switch to your browser and navigate to https:// | * To see your page, switch to your browser and navigate to https:// | ||
+ | |||
+ | ==== Title ==== | ||
+ | * Now let's do the same for ' | ||
+ | * Create a file called ' | ||
+ | < | ||
+ | include(" | ||
+ | include(" | ||
+ | ?> | ||
+ | < | ||
+ | < | ||
+ | <ol> | ||
+ | < | ||
+ | <ul> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ul> | ||
+ | </li> | ||
+ | < | ||
+ | <ol> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ol> | ||
+ | </li> | ||
+ | < | ||
+ | <ul> | ||
+ | < | ||
+ | < | ||
+ | </ul> | ||
+ | </li> | ||
+ | </ol> | ||
+ | |||
+ | < | ||
+ | <ul> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ul> | ||
+ | |||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | <?php | ||
+ | include(" | ||
+ | ?></ | ||
+ | * Notice that we've added < | ||
+ | * Create a file called ' | ||
+ | < | ||
+ | include(" | ||
+ | include(" | ||
+ | ?> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </tr> | ||
+ | </ | ||
+ | < | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </tr> | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </tr> | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </tr> | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </tr> | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | <?php | ||
+ | include(" | ||
+ | ?></ | ||
+ | * Again, notice that we've added < | ||
+ | * Upload both these files to the server and check that they look correct. | ||
+ | * Also notice the ' | ||
+ | * Now change the title in ' | ||
+ | < | ||
+ | * Save and upload ' | ||
+ | * Notice that the title has changed from ' | ||
+ | * Let's also fix our Heading. In ' | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | * Save and upload ' | ||
[[en: | [[en: |