How-to articles, tricks, and solutions about PHP

How can I find the version of php that is running on a distinct domain name?

There are a few ways to find out the version of PHP running on a specific domain name.

MassAssignmentException in Laravel

Here is an example of how a MassAssignmentException might be triggered in Laravel:

Checking for an empty result (PHP, PDO, and MySQL)

In PHP, you can use the PDO (PHP Data Objects) extension to interact with a MySQL database.

How can I disable notices and warnings in PHP within the .htaccess file?

You can disable notices and warnings in PHP by adding the following line to your .htaccess file:

How to validate Google reCAPTCHA v3 on server side?

To validate a Google reCAPTCHA v3 on the server side using PHP, you will need to do the following steps:

Request string without GET arguments

In PHP, you can use the $_SERVER['REQUEST_URI'] variable to get the request string without GET arguments.

How to check whether the user uploaded a file in PHP?

In PHP, you can use the $_FILES superglobal array to check if a file has been uploaded.

WordPress - Check if user is logged in

In WordPress, you can use the function is_user_logged_in() to check if a user is currently logged in.

PHP - get base64 img string decode and save as jpg (resulting empty image )

To decode a base64 encoded image string and save it as a JPG file in PHP, you can use the following code:

When should I use Memcache instead of Memcached?

Memcache and Memcached are both in-memory key-value stores that are commonly used to cache data to improve application performance.

How to let PHP to create subdomain automatically for each user?

To automatically create a subdomain for each user in PHP, you can use the following steps:

What is mod_php?

mod_php is an Apache module that allows PHP code to be executed directly by the Apache web server.

Mysql password expired. Can't connect

If your MySQL password has expired and you can't connect, you will need to reset the password.

Accessing session from TWIG template

In a TWIG template, you can access the session data by using the app.session variable.

How do I count unique visitors to my site?

There are several ways to count unique visitors to a website using PHP, but one common method is to use cookies.

Verify ImageMagick installation

To verify that ImageMagick is installed, you can use the command-line tool "convert".

PHPMailer - SMTP ERROR: Password command failed when send mail from my server

This error message typically indicates that the SMTP server is unable to authenticate the provided login credentials for the email account being used to send the email.

How to resolve ambiguous column names when retrieving results?

When retrieving results in PHP and encountering ambiguous column names, you can use table aliases to specify which table the column belongs to.

Getting title and meta tags from external website

In PHP, you can use the file_get_contents() function to retrieve the HTML code of a website, and then use regular expressions or a DOM parsing library to extract the title and meta tags.

How to remove backslash on json_encode() function?

You can use the JSON_UNESCAPED_SLASHES option in the json_encode() function to prevent backslashes from being added to the JSON string.

How to count days between two dates in PHP?

You can use the DateTime class in PHP to calculate the number of days between two dates.

mysqli or PDO - what are the pros and cons?

mysqli and PDO are both PHP extensions used for interacting with databases.

Best solution to protect PHP code without encryption

One solution to protect PHP code without encryption is to use code obfuscation.

How to get root directory in yii2

In Yii2, you can use the following code to get the root directory:

Installing specific laravel version with composer create-project

To install a specific version of Laravel using the Composer create-project command, you can specify the version number after the package name.