Python-Markdown is a package that converts content in Markdown format to HTML. In this example, we will look at how to convert Markdown to HTML and automatically generate a table-of-contents. We will also look at using the command-line tool to convert content. We will also cover how to use fenced code blocks and
An essential task for most web applications is the ability to take user input. We will look at several common tasks in PHP like:
- How to access GET query parameters from the URL
- How to use forms to submit GET and POST values
- Understanding the security implications of accepting user data and how to protect yourself
- Creating a form to submit GET or POST requests
- Handling checkbox and multi-select fields
- Handing file uploads
There many ways of performing authentication over the web. You can use a token and pass it as a special header. This is commonly done with API tokens. You can also use a cookie to store a session token. This is common for webservers that have a database session in the backend.
One simple method is to use HTTP Basic Access Authentication. This involves adding a header that contains your username and password. The proper format for the header is:
Authorization: Basic XXXXXX
XXXXXX is your credentials in the form of
username:password with base64 encoding.
PHP automatically decodes and splits the username and password into special named constants:
PHP_AUTH_USERwith the username as a plain-text string
PHP_AUTH_PWwith the password as a plain-text string
We will look at how to restrict a page using HTTP basic authentication in PHP.
These examples demonstrate how to work with files in PHP including:
- Reading, writing, and appending files
- Getting file size
- Checking if a file exists
- Creating, checking, changing, and removing directories
- Listing directory contents
- Working with JSON
- Searching directories for files
- Reading and writing compressed files
If you don't have a
favicon.ico file prepared, you can use this simple script
to dynamically generate a PNG file with custom background color and a single
letter in the center. This is convenient as a temporary favicon.
This guide will show you how to perform basic conversion between PHP objects and JSON strings.
Cron jobs are useful for scheduling commands to run periodically. For example:
- Every 15 minutes
- Once per month
In this guide I will show you several common cron tasks and tips that I use including:
- Common scheduling examples
- Chaining together multiple programs
- Redirecting output
- Checking logs
- Running a script from a Python virtual environment
Cron is good for programs that run and then complete, like generating a report, but cron is not for services that stay running forever like a web server. If you want to have a program that continuously runs and you want to ensure the program stays running even if it crashes or the server restarts, you want to setup a service. Check out my tutorial on how to do that: Creating Systemd Service Files.
Cron is available in Linux and Mac operating systems, but not Windows.
If you are using SSH keys with Git to clone and pull your repositories,
you may have to manage several SSH keys.
For example, it is common to setup a "deploy key" in GitHub (
Repository | Settings | Deploy Keys)
that has read-only rights. GitHub also forces you to use unique SSH deploy keys for each repository,
so you have to create a unique SSH keys when you have multiple repositories.
This example shows you how to use specific SSH keys for each remote repository.