Level up your Twilio API skills in TwilioQuest, an educational game for Mac, Windows, and Linux. Download Now
Build the future of communications.
Start building for free
  • By Matthew Setter
    How to Create a Markdown Blog in PHP With the Slim Framework How to Create a Markdown Blog in PHP With the Slim Framework

    When it comes to blogging software, you're not starved for choice. However, despite this choice and how feature-rich modern blogging software is, are the available options necessarily the right choice?

    Sure, software such as WordPress, Ghost, Gatsby, and Wix are very feature-rich — and their UIs are often very smooth. But do you want the hassle of installing, configuring, and securing them on top of writing your blog content? What's more, can you justify the budget that some blogging software requires?

    Maybe, all you want to do is to write your site's content using your preferred editor, using a simple format designed for writing for the web, Markdown, rather than through a user interface.

    If that’s the case, then in this tutorial, I’m going to show you how to create a blog that draws its content from Markdown files. The blog uses the Slim Framework (version 4), the Standard PHP …

    Read More
  • By Matthew Setter
    PHPでHTTPリクエストを実行する5つの方法 PHPでHTTPリクエストを実行する5つの方法

    この記事はMatthew Setterこちらで公開した記事(英語)を日本語化したものです。

    HTTPリクエストは、特にPHPにおいて、最新のWebベースのアプリケーションを特徴付けるものです。開発者は、Google Cloud、Facebook、AWSなど、あらゆる種類の外部サービスやAPIを頻繁に操作する必要があります。極端に言えば、HTTPリクエストは、PHPの基礎の習得後に開発者が最初に学ぶことの1つになるかもしれません。少なくとも私の場合はそうでした。

    そうは言うものの、最新の多くのソフトウェア開発言語と同様に、PHPでHTTPリクエストを実行する方法は複数あります。本稿では、PHPでHTTPリクエストを実行するための5つの方法を紹介します。加えて、それらの使用方法と、それぞれの長所と短所について説明します。詳細を説明するというよりは、それぞれについて広義に紹介していきます。

    本稿で紹介するHTTPリクエストの実行方法は次のとおりです。

    それぞれの方法で、FlickrのAPIを使用し、以下のようなオーストラリアのカカドゥ国立公園の画像を10枚ダウンロードします。

    オーストラリアのカカドゥ国立公園画像

    カカドゥ国立公園のイエロー・ウォーター・ビラボンに沈む夕日、オーストラリア、ノーザンテリトリー州”(Geoff Whalan氏撮影CC BY-NC-ND 2.0に基づく掲載許可)

    必要条件

    チュートリアルを完了するには、以下の項目が必要 …

    Read More
  • By Matthew Setter
    Authenticate Uploads to Amazon S3 in SlimPHP Using Twilio Verify Authenticate Uploads to S3 in SlimPHP Using Twilio Verify

    It's hard to get away from cloud storage in modern web application development; and with good reason!

    Infrastructure as a Service (IaaS) providers such as Amazon Web Services, Microsoft Azure, Google Cloud Platform, and Alibaba Cloud make storing data anywhere in the world almost trivial, regardless of programming language, operating system, and budget.

    Whether you're storing instrumentation data from a Raspberry Pi-based weather station, or medical records for a nation-state, cloud providers are up to the task. However, they don't do everything for you. They won’t handle tasks such as only letting valid users store legitimate files.

    So in this tutorial, you're going to learn how to use Twilio's Verify API to validate uploads to an Amazon S3 bucket in a Slim framework application which uses the Twig templating engine for the view templates.

    Tutorial Requirements

    To follow this tutorial you need the following components:

    • PHP 7.4, …
    Read More
  • By Matthew Setter
    Working with Environment Variables in PHP Working with Environment Variables in PHP

    Environment variables are an excellent way to configure PHP applications because they keep the application’s settings outside of the code. By doing this, it's easier to prevent secure credentials from being exposed, maintain applications, and use applications across multiple environments.

    In this tutorial, you're going to learn about some of the many ways in which environment variables can be set and retrieved in PHP applications. That way, your application can access all the information that it needs, such as API keys, uploaded files, query strings, and form data.

    How to access environment variables in PHP

    Use PHP's Superglobals

    One of the most common ways that environment variables are accessed in PHP is through the use of Superglobals. These are built-in, predefined variables, available in all scopes. Initialised by the PHP runtime, they organise PHP's environment information in a (mostly) logical and efficient way, so that you only need to …

    Read More
  • By Matthew Setter
    Working with Environment Variables in Java Working with Environment Variables in Java

    Environment variables are a great way to configure Java applications without having to explicitly store settings in code, such as for database and caching servers, or for third-party APIs.

    Keeping such settings outside of the code has several distinct advantages:

    • Avoids the need to update and recompile code when settings change
    • Helps prevent exposing sensitive credentials, such as usernames and passwords, and deployment tokens
    • You can deploy the same code in multiple environments

    In this short article, I'm going to show you some of the ways of working with environment variables in Java.

    How to access environment variables in Java

    One of the most common ways is to use System.getenv(), which accepts an optional String argument. Based on whether a String argument is passed, a different value is returned from the method. Specifically:

    If a String is passed and it matches a key in the internal environment Map, …

    Read More
  • By Matthew Setter
    How to Create a QR Code in PHP How to Create a QR Code in PHP

    QR codes are almost everywhere these days!

    It makes sense. They're small, readable on any modern smartphone without special software, and let us do so many things easily and quickly, such as checking in at a cafe, gaining access to a WiFi network, accessing a scooter on a summer vacation, and making a purchase.

    Here are some examples that I found from around the web.

    Some examples of QR codes.

    So if you want to know how to create them in your PHP-based application, read on.

    Prerequisites

    To follow this tutorial, you need the following:

    • Previous experience with writing PHP code.
    • PHP 7.4 with the GD extension installed.
    • Composer installed globally.
    • A smartphone.

    Let's create a QR code in PHP

    First, we need to create a project directory structure to store all the files that we'll make use of. To do so, switch into the top-level directory, and run the commands below.

    mkdir -p php-qr-code-generator …
    Read More
  • By Matthew Setter
    Build a PHP Phone Number Validator Using Twilio and laminas-validator Build a PHP Phone Number Validator Using Twilio and laminas-validator

    No matter where your data comes from — a user, database, an environment variable, or somewhere else entirely — it must be validated. If not, how can you be sure that it's valid?

    This is such an important and accepted part of modern software development that all of the major PHP frameworks, such as Laravel, Symfony, and Mezzio provide a validation component. If you're not using a framework, Composer can quickly integrate a third-party library such as laminas-validator.

    However, what if a validation library or a framework's validation component doesn't support a validator that matches your use case? In that case, it's time to write a custom validator.

    In this tutorial, I'm going to show you how to write a custom phone number validator for laminas-validator using Twilio's Lookup API.

    Tutorial Requirements

    To follow this tutorial you need the following components:

    Read More
  • By Matthew Setter
    Build a Phone Number Validator with Laravel Build a Phone Number Validator with Laravel

    Data validation is essential to any application, regardless of its size and purpose. Without it, you risk using data that's forged by malicious actors, contains only junk—or is a combination of both. And it doesn't matter where the data comes from either; whether from a web form, retrieved from a database, or read from an environment setting.

    Gladly, validation is extremely common in modern software development, so much so that there are numerous third-party packages available on Packagist, and PHP's major frameworks all have a validation component. With them, you can validate email addresses, passwords, dates, IP addresses, numbers and so much more!

    However, what happens when the package or framework doesn't support your use case, such as validating a phone number? In that case, you roll your own!

    In this tutorial, we're going to build a custom Laravel validation rule object that validates a phone number from any country …

    Read More
  • By Matthew Setter
    How to Lookup Phone Numbers in Plain PHP With Twilio's Lookup API How to Lookup Phone Numbers in Plain PHP With Twilio's Lookup API

    Phone numbers are a very common part of user profiles in modern applications. For example, they let users receive an OTP (One Time Password) to log in to an account or receive a recovery code when they can't access their second-factor device, and they let support staff contact a customer when there is suspicious activity on their account.

    However, how often do we check that the phone number which users store in their profiles is genuine? Today, I'm going to show you how to do it in plain PHP using Twilio's Lookup APIno framework required!

    Tutorial requirements

    To follow this tutorial you'll need three things:

    Create the project directory and install the …

    Read More
  • By Matthew Setter
    Build a WhatsApp Chatbot with PHP, Mezzio, and Twilio Build a WhatsApp Chatbot with PHP, Mezzio, and Twilio

    A chatbot is a software application that a person can have a conversation with, either in written or spoken form. That said, their capacity to have a conversation often varies greatly. For example, some chatbots can only answer quite a limited set of specific questions (sometimes in a fixed order). Others, however, use a combination of artificial intelligence (AI) and machine learning (ML) to interact almost as a human could.

    In this tutorial, I'm going to show you how to build a small, simplistic chatbot using the Twilio API for WhatsApp, the Mezzio framework for PHP, and the Weather API to retrieve the current weather forecast for any city around the world.

    How will the chatbot work?

    Before we dive in and write code, let’s get a quick overview of how the chatbot will work. In essence, here’s the logic of the project:

    1. A user will send a …
    Read More
  • Newer
    Older
    Sign up and start building
    Not ready yet? Talk to an expert.