- Saved searches
- Use saved searches to filter your results more quickly
- banago/simple-php-website
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- readme.md
- Your first PHP-enabled page
- How to code your first PHP Web Page
- PHP Usage Stats:
- Syntax of PHP:
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
An introductory example of how to build a simple and minimal website built with PHP.
banago/simple-php-website
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
The site is now resposnive for mobiles Fixes and PHP notice for query strings Docs update to add running the site on PHP local server
Git stats
Files
Failed to load latest commit information.
readme.md
I put together this project while introducing a friend of mine to PHP. I decided to clean it up a bit and put it on Github so anyone new to PHP can have a taste of a very simple and minimal website built with PHP.
This project is meant for beginners. I’ve intentionally kept it minimal while introducing some separation of concerns.
There are only two steps to run this website:
- Download the project to the desired directory on your computer
- Run php -S localhost:8080 on your terminal. Navigate to http://localhost:8080 to see the site.
By defaut, the page URLs use query strings (?page=about). You need to have Apache installed for pretly URLs (/about) to work. To activate pretty urls, update config value of pretty_uri to true .
The project covers these programming concepts:
- Variables
- Arrays
- Functions
- Pretty links (/about) with fallback to query string (?page=about)
- Basic example of separation of concerns (functionality, template, content)
If you have any questions or recommendations for the project, please create an issue or hit me up on Twitter @banago.
To help you take your knowledge of PHP to the next level, I’ve personally hunt down what I deem to be the best introductory course on PHP out there. I wish this course existed when I started learing PHP. Check it out on Udemy: PHP for Beginners Course.
Your first PHP-enabled page
Create a file named hello.php and put it in your web server’s root directory ( DOCUMENT_ROOT ) with the following content:
Example #1 Our first PHP script: hello.php
Use your browser to access the file with your web server’s URL, ending with the /hello.php file reference. When developing locally this URL will be something like http://localhost/hello.php or http://127.0.0.1/hello.php but this depends on the web server’s configuration. If everything is configured correctly, this file will be parsed by PHP and the following output will be sent to your browser:
This program is extremely simple and you really did not need to use PHP to create a page like this. All it does is display: Hello World using the PHP echo statement. Note that the file does not need to be executable or special in any way. The server finds out that this file needs to be interpreted by PHP because you used the «.php» extension, which the server is configured to pass on to PHP. Think of this as a normal HTML file which happens to have a set of special tags available to you that do a lot of interesting things.
If you tried this example and it did not output anything, it prompted for download, or you see the whole file as text, chances are that the server you are on does not have PHP enabled, or is not configured properly. Ask your administrator to enable it for you using the Installation chapter of the manual. If you are developing locally, also read the installation chapter to make sure everything is configured properly. Make sure that you access the file via http with the server providing you the output. If you just call up the file from your file system, then it will not be parsed by PHP. If the problems persist anyway, do not hesitate to use one of the many » PHP support options.
The point of the example is to show the special PHP tag format. In this example we used . You may jump in and out of PHP mode in an HTML file like this anywhere you want. For more details, read the manual section on the basic PHP syntax.
Note: A Note on Line Feeds
Line feeds have little meaning in HTML, however it is still a good idea to make your HTML look nice and clean by putting line feeds in. A linefeed that follows immediately after a closing ?> will be removed by PHP. This can be extremely useful when you are putting in many blocks of PHP or include files containing PHP that aren’t supposed to output anything. At the same time it can be a bit confusing. You can put a space after the closing ?> to force a space and a line feed to be output, or you can put an explicit line feed in the last echo/print from within your PHP block.
Note: A Note on Text Editors
There are many text editors and Integrated Development Environments (IDEs) that you can use to create, edit and manage PHP files. A partial list of these tools is maintained at » PHP Editors List. If you wish to recommend an editor, please visit the above page and ask the page maintainer to add the editor to the list. Having an editor with syntax highlighting can be helpful.
Note: A Note on Word Processors
Word processors such as StarOffice Writer, Microsoft Word and Abiword are not optimal for editing PHP files. If you wish to use one for this test script, you must ensure that you save the file as plain text or PHP will not be able to read and execute the script.
Now that you have successfully created a working PHP script, it is time to create the most famous PHP script! Make a call to the phpinfo() function and you will see a lot of useful information about your system and setup such as available predefined variables, loaded PHP modules, and configuration settings. Take some time and review this important information.
Example #2 Get system information from PHP
How to code your first PHP Web Page
PHP is one of the most popular programming languages for web development. It is offered nearly ubiquitously on shared hosting platforms. Many of the world’s leading content management systems, such as WordPress, Joomla, Drupal, Magento, Prestashop and lots of other most visited sites like Facebook, Wikipedia, Baidu, Yahoo!, Tumblr, Flickr, MailChimp, Fotolia, Digg, iStockPhoto and many more are written in PHP. Fortunately for developers, learning PHP is not exceptionally challenging. Like learning any skill it requires practice and patience. The first step is to understand what PHP is. Then the next step is to learn how to write a simple PHP web page.
[bctt tweet=”How to code your first PHP Web Page”]All PHP pages are executed on the server. When a user visits your PHP page with their web browser, the web server opens and reads your PHP script. It then prepares an output to send to the web browser. For this reason, PHP scripts typically include database calls and business logic calculations. These are typical aspects of your site that you want to hide from the general public. You don’t want anyone to be able to see your database structure, as that may give them ideas on how to hack it. These scripts also frequently handle form submissions as well. When you fill out a web form online, you may be sending that information to a PHP script for insertion into the user database.
PHP Usage Stats:
PHP is the scripting language of future. As reported by various aggregators and surveys like one by W3Techs PHP is one of the top most scripting language used worldwide. Moreover, its popularity and usage is increasing day by day with every new version.
In order to run PHP applications, you will need to have a web server that is configured to serve these types of pages. If you have a shared hosting environment, this will typically be included as part of your hosting package. If you have cloud hosting, you may need to install both Apache and PHP to see your pages. Windows users can install a software package called XAMPP to get a both a PHP web server and database on their local computer. Similarly, Mac OS X users can install MAMP which includes a PHP server and database. These are free and simple methods of installing an environment to run and test your PHP pages.
[call_to_action color=”gray” button_icon=”download” button_icon_position=”left” button_text=”Download Now” button_url=”https://templatetoaster.com/download” button_color=”violet”]BEST DRAG AND DROP BEST WEB DESIGN SOFTWARE
[/call_to_action]
Syntax of PHP:
The syntax of PHP is relatively simple. Code your web page as you normally would, but all PHP code must be enclosed in “”. The following program outputs “Hello World” into your web browser.
Save the above code to a file called example1.php and upload it to your web server. Then visit that page in your web browser. You will see “Hello World” on your screen.
PHP contains far more exciting features than just outputting static text. Variables store values within a PHP script, and they are defined with dollar signs in front of them. Therefore, “$number” can hold a value such as 1 or -10. The following code adds four and five. The result is displayed to the user.
Functions are a way of defining common routines or calculations so that the same code doesn’t need to be written in multiple locations. Each function has input parameters and a returned value. The following code defines a function that takes two numbers as input parameters and returns the sum of them.
The following code uses the function above to display the results of four plus five and six plus seven.
PHP is a very versatile and advanced scripting language that is capable of handling from basic php web pages to advanced web applications. Database-driven web pages, user authentication, and shopping carts can easily be coded through PHP. It is also a highly marketable job skill as many companies rely on full-time PHP developers to power their web infrastructure. Learning PHP enables you to build powerful websites for any idea. you may also read PHP cheat sheet.
If you don’t want to learn PHP: If you want to start your career as a Web Designer or need to have your own website but don’t want to learn PHP and HTML/CSS just download TemplateToaster to create your own website. It is a web design software for designing stunning WordPress, Joomla, Drupal, Magento, Prestashop and Blogger Themes. I hope you enjoyed this article, let me know your thoughts through comments.