Let's go ahead and look at web publishing dynamically with PHP. I'm going to go ahead and take my static file from the last project and I'm just going to copy it into the 04 Video Folder. And then what I'm going to do is open that up in my code editor so that we can take a look at how we would actually put PHP code in here and how the server will handle that code differently from the HTML. First of all let's go ahead and open this up in our browser. So we'll go to the 01 Folder and then 04 and here's our static HTML. Let's go ahead and put some PHP code in here and I don't expect you to know exactly what we're doing when it comes to PHP. But I'm just going to show some sample code so that you can understand the difference in how dynamic publishing works than static publishing. Let's go ahead and find a good spot to make an entry and we'll do this right above the Something Else text here. So right before this break tag I'm going to go ahead and put in some code here but instead of HTML code I'm going to put PHP code. So here's my two tags which tell the web server that I'm starting PHP code and ending PHP code. Then what I'm going to do is I'm going to set a variable and the variable X is going to be equal to 40 times 12. I'm just picking some numbers here. And then what we're going to do is we're going to go ahead and output that X is equal to and then we'll put the variable there and it will substitute the value of that variable when the PHP code is processed. Now let's go ahead and refresh our page. We don't see any output here at all, nothing's changed. But if we look at the source code you'll scroll down and you'll see that our PHP code is visible when we look at the source of the code. This is really important to understand that when PHP has not been processed it will be visible in the source code, in the browser. This is very important because a lot of times in your PHP code you'll put information in there, you might put usernames, you might put passwords, you might put URLs you might put file paths. A lot of information that you absolutely do not want the user to see and if it's sent to the browser, then when they look at the source code, they're going to see all that information. The reason why the PHP code is visible here is because it wasn't processed which is exactly why we didn't see any output here. So that's an example of how you put PHP code in there. But it's not an example of dynamic processing. You see what has happened is the web server has looked at this file as if it was just a plain HTML file and then sent it directly to the browser. What we want the web server to do is know that this file contains PHP code, send the file contents to the PHP processor where this PHP code or any PHP code in this document will get preprocessed. And then only the output which would be this Echo Statement will be given back to the web server with all the HTML which the PHP processor will actually skip over. And then the web server will send all the results to the browser. So how do we tell the web server that this is a dynamic web page, it contains PHP code and it needs to be processed? You do this simply by changing the extension of the file from HTML to PHP. So now we have Static.php. I'll confirm I do want to use that extension and now we'll go ahead and close this and refresh our page. And of course it can't find it because I'm trying to point it to Static.html. But we want it to go to Static.php. Here you can see that the PHP code has been processed and that X is equal to 480. Furthermore if we look at the source code we'll scroll down to where that output is and you can see that no PHP code was sent out to the browser. Only the results of the PHP code. So again very important to understand for security purposes that PHP code is preprocessed and only your outputted code is sent to the browser. But if you do not have the page processed by the PHP processor, then you're going to be outputting to the browser all of your PHP code. So something definitely to be aware of. So here's a great example of dynamic web publishing. We're simply processing code on the server side so we can dynamically generate output and then we're sending that output out to the browser. All you need to do is remember that any file that contains PHP code has the .php extension.
| Course: | FileMaker and PHP Foundations |
| Author: | Lance Hallberg |
| SKU: | 34393 |
| ISBN: | 978-1-61866-077-0 |
| Release Date: | 2012-12-07 |
| Duration: | 7.5 hrs / 97 lessons |
| Work Files: |
Yes |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |