Validate phone number and email in php

Phone number validation using regular expression

$user_phone = $_POST['user_phone'];

if(!preg_match('/^([0-9]+)$/', $user_phone))
{
    $_SESSION['info']="Please enter valid phone number";
    header('location:/register');
}

Phone number validation using is_numeric function

$user_phone = $_POST['user_phone'];
if(!is_numeric($user_phone))
{
    $_SESSION['info']="Please enter valid phone number";
    header('location:/register');
}
if (filter_var($user_email, FILTER_VALIDATE_EMAIL) == false){
    $_SESSION['info']="Please enter valid email";
    header('location:/register');
}
  • is_int or is_integer
  • is_numeric
  • regular expressions
  • ctype_digit
  • filter_var

is_integer()

for this function these values are are not valid: “0010”, “123”

is_numeric()

for this function these values are valid: 1.3, +1234e44 and 0x539

filter_var()

for this function a value as “00123” is not valid

CONSLUSION

it seems that only regex and ctype_digit work always fine.

Invalid or missing Livepatch token

  1. Disable Livepatch either through the GUI or by running canonical-livepatch disable as root
  2. Uninstall Livepatch with snap remove canonical-livepatch as root (optional. Try it first without doing this)
  3. Run the command rm /etc/machine-id as root to remove your current machine ID (if it says the file or directory doesn’t exist, you can safely ignore it)
  4. Run the command systemd-machine-id-setup as root to regenerate the ID
  5. Reinstall Livepatch with snap install canonical-livepatch as root (if you removed it earlier)
  6. Either grab your key from https://auth.livepatch.canonical.com and follow the instructions there to re-enable or use the Livepatch GUI

check ubuntu version

lsb_release -a

Upgrade Ubuntu

sudo apt upgrade

Unable to upload large file in website

Unable to upload large file in php website, here is setting for htaccess file, after this you can upload 500 mb file size, and also change this value.

php_value upload_max_filesize 5000M
php_value post_max_size 5000M
php_value memory_limit 256M
php_value max_execution_time 300
php_value max_input_time 300

404 redirect to homepage wordpress

if( !function_exists('redirect_404_to_homepage') ){

    add_action( 'template_redirect', 'redirect_404_to_homepage' );

    function redirect_404_to_homepage(){
       if(is_404()):
            wp_safe_redirect( home_url('/') );
            exit;
        endif;
    }
}

WordPress best performance .htaccess file content

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript


#BEGIN EXPIRES HEADERS
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default expiration: 1 hour after request
ExpiresDefault "now plus 1 hour"
# CSS and JS expiration: 1 week after request
ExpiresByType text/css "now plus 1 week"
ExpiresByType application/javascript "now plus 1 week"
ExpiresByType application/x-javascript "now plus 1 week"
# Image files expiration: 1 month after request
ExpiresByType image/bmp "now plus 1 month"
ExpiresByType image/gif "now plus 1 month"
ExpiresByType image/jpeg "now plus 1 month"
ExpiresByType image/jp2 "now plus 1 month"
ExpiresByType image/pipeg "now plus 1 month"
ExpiresByType image/png "now plus 1 month"
ExpiresByType image/svg+xml "now plus 1 month"
ExpiresByType image/tiff "now plus 1 month"
ExpiresByType image/vnd.microsoft.icon "now plus 1 month"
ExpiresByType image/x-icon "now plus 1 month"
ExpiresByType image/ico "now plus 1 month"
ExpiresByType image/icon "now plus 1 month"
ExpiresByType text/ico "now plus 1 month"
ExpiresByType application/ico "now plus 1 month"
# Webfonts
ExpiresByType font/truetype "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
</IfModule>
#END EXPIRES HEADERS

# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
 <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
 Header set Cache-Control "max-age=2592000, public"
 </filesMatch>
 <filesMatch "\.(css)$">
 Header set Cache-Control "max-age=604800, public"
 </filesMatch>
 <filesMatch "\.(js)$">
 Header set Cache-Control "max-age=216000, private"
 </filesMatch>
 <filesMatch "\.(x?html?|php)$">
 Header set Cache-Control "max-age=600, private, must-revalidate"
 </filesMatch>
</ifModule>
# END Cache-Control Headers


# ENABLE LITESPEED CACHE START
<IfModule LiteSpeed>
CacheEnable public
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^GET|HEAD$
RewriteCond %{HTTP_HOST} ^sample.com|sample.net|sample.org [NC]
RewriteCond %{REQUEST_URI} !login|admin|register|post|cron
RewriteCond %{QUERY_STRING} !nocache
RewriteRule .* - [E=Cache-Control:max-age=300]
</IfModule>
# ENABLE LITESPEED CACHE END

# START ENABLE KEEP ALIVE
<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>
# END ENABLE KEEP ALIVE


<IfModule pagespeed_module>
ModPagespeed on
ModPagespeedEnableFilters rewrite_css,combine_css
ModPagespeedEnableFilters recompress_images
ModPagespeedEnableFilters convert_png_to_jpeg,convert_jpeg_to_webp
ModPagespeedEnableFilters collapse_whitespace,remove_comments
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

Step by step overview guide for setup business WhatsApp API

Step by step overview guide for setup business WhatsApp API with Facebook business account

What is the criteria to check my business Facebook is active for WhatsApp api

after that your WhatsApp api is fully activated.

  1. Must have Facebook business account setting
    a. WhatsApp account added into Facebook business setting
    b. Add system user
    c. Assign an App to system user via add assets
    d. Generate token for final use of WhatsApp api with selected permission
  2. Create app and add it into business Facebook account
    Note : for use WhatsApp api app type must be business

*Step by step overview guide for setup business WhatsApp API
*What is business WhatsApp API
*How to implement WhatsApp API

#1101 error in mysql / phpmyadmin

1101 – BLOB, TEXT, GEOMETRY or JSON column ‘answer’ can’t have a default value

Probably your development environment allows the defaults and the production environment doesn’t. You can either upgrade your production system or not use that feature.

How to disable strict mode in MySQL 5 (Windows):

  • Edit /my.ini and look for linesql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
  • Replace it withsql_mode='MYSQL40'
  • Restart the MySQL service (assuming that it is mysql5)net stop mysql5 net start mysql5

If you have root/admin access you might be able to execute

mysql_query("SET @@global.sql_mode='MYSQL40'");

#2006 – MySQL server has gone away

MySQL/MariaDB related:

  • wait_timeout – Time in seconds that the server waits for a connection to become active before closing it.
  • interactive_timeout – Time in seconds that the server waits for an interactive connection.
  • max_allowed_packet – Maximum size in bytes of a packet or a generated/intermediate string. Set as large as the largest BLOB, in multiples of 1024.

Example of my.cnf:

[mysqld]
# 8 hours
wait_timeout = 28800
# 8 hours
interactive_timeout = 28800
max_allowed_packet = 256M

If you are using xampp server :

Go to xampp -> mysql -> bin -> my.ini

Change below parameter :

max_allowed_packet = 500M

innodb_log_file_size = 128M