How-to articles, tricks, and solutions about PHP

How validate unique email out of the user that is updating it in Laravel?

In Laravel, you can use the unique validation rule to validate that an email address is unique when a user is updating their account.

How to access the php.ini from cPanel?

To access the php.ini file from cPanel, you can follow these steps:

How to print exact sql query in zend framework ?

In Zend Framework, you can use the Zend_Db_Select object's __toString() method to print the exact SQL query that will be executed.

Best way to store passwords in MYSQL database

The best way to store passwords in a MySQL database is to use a one-way hashing algorithm, such as bcrypt or scrypt, to hash the password before storing it in the database.

Remove all non-numeric characters from a string; [^0-9] doesn't match as expected

You can use the preg_replace function in PHP to remove all non-numeric characters from a string.

Check if number is decimal

In PHP, you can use the is_float() function to check if a variable is a decimal number.

Fatal error: Call to undefined function: ldap_connect()

This error message is indicating that the PHP function ldap_connect() is not defined or not available.

phpMyAdmin allow remote users

phpMyAdmin is a web-based tool for managing MySQL and MariaDB databases.

"Typed property must not be accessed before initialization" error when introducing properties type hints?

In PHP, the "Typed property must not be accessed before initialization" error is encountered when a property is defined with a type hint, but it is accessed before it has been explicitly assigned a value.

How to set a class attribute to a Symfony2 form input

In Symfony2, you can set the class attribute of a form input by using the "attr" option in the form field configuration.

Fatal error: Call to undefined function imap_open() in PHP

This error message indicates that the PHP script you are running is trying to use the imap_open() function, but it is not defined or not enabled in your PHP configuration.

Populate a Drop down box from a mySQL table in PHP

You can use the PHP MySQLi extension to connect to a MySQL database and retrieve the data from a table to populate a drop-down box.

Checking if a variable is an integer in PHP

In PHP, you can use the is_int() function to check if a variable is an integer.

phpmailer - The following SMTP Error: Data not accepted

The "SMTP Error: Data not accepted" is a common error message that can occur when using the PHPMailer library to send email messages.

best practice to generate random token for forgot password

A common practice for generating a random token for a "forgot password" feature in PHP is to use the built-in functions random_bytes and bin2hex.

Block direct access to a file over http but allow php script access

One way to block direct access to a file over HTTP but allow PHP script access is to use a .htaccess file in the same directory as the file.

utf-8 special characters not displaying

This issue is likely caused by a mismatch between the character encoding used by the source of the text (e.g.

How to display a date as iso 8601 format with PHP

You can use the date() function in PHP to display a date in ISO 8601 format.

Clearing content of text file using php

To clear the contents of a text file using PHP, you can use the file_put_contents() function.

MySQL server has gone away - in exactly 60 seconds

The "MySQL server has gone away" error message typically indicates that the connection to the MySQL server was lost.

HTML Upload MAX_FILE_SIZE does not appear to work

In PHP, you can use the $_FILES array to check the size of an uploaded file.

How to display Woocommerce Category image?

To display a category image in WooCommerce, you can use the woocommerce_subcategory_thumbnail hook in your theme's functions.php file.

Laravel migration table field's type change

To change the type of a field in a table using a migration in Laravel, you can use the change method on the Schema facade.

PHP header redirect 301 - what are the implications?

A 301 redirect in PHP using the "header" function tells the browser that the page has permanently moved to a new location.

The CSRF token is invalid. Please try to resubmit the form

This error message is typically related to a security feature called "Cross-Site Request Forgery" (CSRF) protection.