Getting Started With PHP
Getting Started With PHP
An Overview and What It’s Used For
If you are interested in web development, in particular designing web applications, then at some point you most likely will need to use PHP. This article centers more around the concepts associated with PHP, and how it is useful in regards to web development. We will not be covering how to program in PHP, but useful tutorials and information can be found at W3Schools and Codecademy. If you are new to web development, these are free resources that we recommend you check out, as they are priceless resources and will be very helpful throughout your web journey.
What It’s Used For
Embedding Within HTML Markup
As mentioned above PHP is used to make web pages more modular as well as communicate between the server and the client. One of its best features is its capability to be embedded inside HTML Markup, which provides us with several benefits. The first being that people who visit your web page can not see the code that is processed on the server. Say we visit a website. We can view the page source as seen below…
From this view, we can see all of the HTML and JS elements on the page. However, there might be some content we don’t want people visiting our site to see. We can hid this content with PHP. Furthermore, PHP’s ability to be embedded in HTML comes in handy when we have some HTML that we use often. Instead of typing it out every time, or even copy-pasting, we can have it inside a PHP file and simply include it within our other files. For example, say we have a navigation bar that we want to include at the top of every page on our website. We can have a template of that navigation bar that we just reference at the top of every page. So, this not only makes our websites more modular, but makes our source code easier to read. For more in depth examples and information you can find more in our article “Getting Started With PHP: Making Web Pages More Modular“.
Relaying information Between Client and Server
Servers, especially for sites that have memberships or subscribers need to be able to receive and store information about the site’s users. However, web servers can not interact with the website directly. That’s where PHP comes in. Since PHP is a server side language that can be embedded within HTML, it’s the perfect tool for relaying information between the client and the web server.
First, let’s focus on the transferring of data from the client to the web server. The most common instance of this type of transfer is through the use of forms. The form is created with HTML, the data that the client submits is then processed by PHP, and then finally it’s sent to the server to be stored. This can be seen in our article “Getting Started with PHP: Creating a Simple Request Form“.
The other scenario is when information is sent from the server to the client. A good example of this is a user profile. The client will log in (which is submitted via a form), and then based on the information provided to the server about the user, it will send specified stored information about the user back to the browser. So, while the code on the page remains the same, each user will see their own profile picture and data, because that’s the information stored on the server relevant to their username and password. While this is probably the most common form of the server to client process it is just an example. The same process is used any time we need to send information from the server to the browser.
Handling User Cookies and Sessions
If you’ve ever wondered how a website knows who you are, knows to prompt you to log in, or knows that you have already done so, the answer is through ‘cookies’ and ‘sessions’. Both of these are ways for the web page to know who is currently visiting it, however, there are some distinct differences between the two.
Sessions on the other hand, are used as a way to store information to be used across multiple pages. Unlike cookies, sessions store the information in variables, not on the users computer. When we log onto a website, we are able to visit multiple pages without having to log in on every page though the use of session variables. They store our login information and last until we close the browser, which allows our user information to be used across multiple pages.
In conclusion, PHP has a wide variety of uses. It allows us to hide content if we want, share information across multiple pages, and most importantly, interact with the web server. All our stored information on the server is accessed through PHP, it allows us to reuse code, and makes our sites more modular. It’s a critical component to web development and many web platforms such as WordPress are built off of it. We hope this article has given you some insight into PHP and how it is useful. If you’re interested in learning more, or want to get started using PHP for web development, check out our article “Getting Started With PHP: Setting Up Your PHP Environment“.