Servage Magazine

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

Articles Tagged ‘php’

Permission Management in PHP with Bouncer

Saturday, October 21st, 2017 by Servage
php7Permission management doesn’t sound like an easy task. Fortunately, a PHP package called Bouncer makes it rather simple. Bouncer not only handles permissions but also user groups, and you can assign permissions to those groups. For example. You can allow editors to create blog posts with only a few lines of code. Installing Bouncer Since Bouncer is a PHP package, to no surprise it can be installed using Composer by running “composer require silber/bouncer”. Bouncer is a Laravel package so therefore it only works with Laravel projects. As usually with Laravel packages, you have to add the new package to the providers array of config/app.php: “Silber\Bouncer\BouncerServiceProvider::class”. Also add the following to the aliases ...

What has changed in Laravel 5.5?

Monday, September 18th, 2017 by Servage
laravelA new major version of Laravel is scheduled for release in late August 2017. In addition to being a long-term support release, many new features will be added to the framework, including a new error handler, custom validation rules, a new Artisan command and more. Let’s have a closer look at these new features. The “migrate:fresh” Command In previous versions of Laravel, the migrate:refresh command has been used as a quick way to roll back all changes made to a database. What it does is simply execute the down() method of all migrations followed by the up() method. The new command migrate:fresh does the same but skips calling the down() method first. In many ...

PHP best practices for using Traits and Interfaces

Thursday, August 10th, 2017 by Servage
php-codeDo you often notice yourself ending up writing the same code in multiple files? Do you wish you could force similar classes to follow the same structure? Traits and interfaces are something new PHP developers tend to overlook, but they are perfect in solving problems like these. Traits: An Alternative to Multiple Inheritance Traits have been available in PHP since 5.4. A trait is a PHP file that uses the trait keyword instead of class. Traits and classes are quite similar: classes can be extended and traits can be used inside other classes to prevent having to write same code twice in different files. Instead of writing the same method for two classes, ...

Things that every PHP developer should know

Saturday, August 5th, 2017 by Servage
phpThe PHP ecosystem is relatively simple to keep up-to-date on once you know your way around it. The ecosystem has not changed as significantly as let’s say JavaScript over the past few years. However, there are some concepts every developer should be familiar with, as well as some tools that have become standards in PHP. Let’s have a look at these things you should be familiar with as a PHP developer. Composer Composer is the first thing that comes to the mind of developers when they have to name one great thing about PHP. Composer is a package and dependency manager tool for PHP, and it makes working with external libraries much easier ...

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 ...