Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Articles Tagged ‘php’

What is new in PHP 7.1?

Monday, June 12th, 2017 by Servage
php-7-1PHP 7.1 was released at the end of 2016 and web servers are being upgraded to support the latest additions to the language. This is a good moment for developers to see what new features have been added to PHP in the newest version. Void Return Type Let’s start with something small and simple. PHP already has support for function return types, excluding the void data type. A void return type means that no value is returned from a function. In version 7.1, you can indicate this in the function signature by using the typical colon syntax that already works with other return types: protected function foo(string $value): void {}. Nullable Types PHP also already ...

Protecting users with Two-Factor Authentication

Thursday, May 11th, 2017 by Servage
two-factorTwo-factor authentication (2FA) is considered the most secure way to protect online accounts. It protects user accounts with one-time codes that are usually delivered to the user with a 2FA application or text message. Big companies, such as Google, Facebook and Microsoft, already support 2FA, and it continues to gain more support on smaller websites too. This time we will see what it takes to implement two-factor authentication on a website using PHP. Installing pragmarx/googlef2a To set up two-factor authentication, we will be using a popular Composer package called pragmarx/google2fa. To get started, install the package using Composer: “composer require pragmarx/google2fa”. This requires you to have composer installed globally as described on www.getcomposer.org. Updating ...

PayPal integration with PHP

Sunday, May 7th, 2017 by Servage
paypalAccepting payments is quite common on business websites. There are many payment processors to choose from, but PayPal has been the leading payment processor for a long time. Implementing a shopping cart or checkout system on a website is not a simple task, but with these instructions you should be able to integrate a simple single-item checkout process with your own website. Making a Payment Button First, we have to make a payment button that a customer can click to pay their order. PayPal offers multiple buttons for adding a product to a shopping cart, creating a subscription payment, and so on. For buying a single item, the buy now button is the ...

Code linting explained

Friday, March 17th, 2017 by Servage
codeLinting is a term you hear every now and then, but what does it mean? Linting is related to source code analysis, which is something you should do for your code as you develop. After reading this article you will be more familiar with these things. Let’s find out what linting is and how to do it with CSS, JavaScript and PHP code. Linting Explained So, what is this mysterious “linting” people are sometimes talking about? Simply put, linting is a code review method where a program automatically analyses source code to detect issues. Lint was the name given for a C program that was used for this type of code analysis decades ...

Using Active Directory for LDAP Authentication in PHP

Wednesday, February 8th, 2017 by Servage
UnknownActive Directory (AD) is a tool you can often find in enterprises where it is used to authenticate and authorize users. It works as a single-sign-on service where only one user account is needed to sign in to multiple services. AD can be used to authenticate users for PHP applications as well. Active Directory is often considered difficult to understand or use, but soon you will see how easy it is to integrate it with websites. LDAP Functions Now here comes the easy part: authenticating users. Why is it easy? Well, because PHP comes with built-in functions called ldap_connect() and ldap_bind(), which are exactly what we need to authenticate users against Active Directory. ldap_connect() ...

Performing email-verification in PHP

Sunday, February 5th, 2017 by Servage
email-verificationEmail verification is a feature found on almost every website with a login system. Some PHP frameworks come with a built-in email verification, but in case you are using one that does not, you will have to use some other ready-made solution like a library or to build it from scratch. Building the system by yourself also gives you more freedom and flexibility to customize it for your needs. The Process Explained Here is how email verification often works in PHP applications: When a user signs up, their data, such as email address, password and name, are inserted into a database. Along with this data, a unique email verification token is stored in ...

How to scrape content from the web

Wednesday, February 1st, 2017 by Servage
imagesWeb scraping is a technique to extract data from a web page. The data can be text, images, hyperlinks or anything else found on websites. Today we will look into what web scraping is and why and in what situations it may be useful. We will also meet Gouette, a PHP web scraper library. How Web Scraping Works Web scraping starts by sending a GET request to a URL like a browser normally does when you visit a website. When the request is sent, the HTML response is saved so that it can be parsed and data can be extracted from it. When to do Scraping In desired situations, the website you want to get ...

Handling file-uploads with PHP

Thursday, January 12th, 2017 by Servage
Upload-FilesSending files with an HTML form is quite common on websites these days. When using a help desk, you can often attach a screenshot of the issue to help customer service assist you easier. When applying for a job online, you can attach your CV to the application. In both of these cases, the attached files are processed by a server and saved to a specific location. Let’s see what it takes to build a form like this with file uploading capabilities using PHP. The HTML Let us first get started with the required HTML. All we need is a typical form with a file input field. The input field can look like ...

PSR coding-standards for PHP

Wednesday, December 28th, 2016 by Servage
phpWhen PHP 1.0 was released in 1995, there were no common standards or code style preference for the language.  This continued to be the case until 2009 when PHP PSR (PHP standard recommendation), a set of standards was finally introduced to the language. The recommendations consist of multiple standards, so let's see what the major ones are. PSR-1: Basic Coding Standard The basic coding standard defines a set of rules that all PHP files should follow. The purpose of it is to make shared PHP code as compatible as possible with other projects and environments where the code is executed. For example, you should only use the full <?php or short-hand <?= tags in ...

Introduction to WebSockets

Wednesday, December 21st, 2016 by Servage
WebSocketsDid you know it is possible to build real-time applications using only PHP? This is possible, thanks to a protocol called WebSocket. WebSockets allow a client and server to remain connected and exchange data in both directions without having to reload a web page. It does not matter whether you are a front-end or back-end developer since WebSockets are available in HTML5, JavaScript, PHP and many more languages and platforms. How WebSockets work WebSockets use the TCP protocol on port 80, which is the same port HTTP uses. By definition, WebSocket is a full-duplex protocol, meaning both ends of the connection can talk at the same time without interrupting each other. But how ...