Skip to main content

Posts

Showing posts from September, 2017

What is an earthquake?

Earthquakes with magnitude of about 2.0 or less are usually called microearthquakes; they are not commonly felt by people and are generally recorded only on local seismographs. Events with magnitudes of about 4.5 or greater - there are several thousand such shocks annually - are strong enough to be recorded by sensitive seismographs all over the world. Great earthquakes, such as the 1964 Good Friday earthquake in Alaska, have magnitudes of 8.0 or higher. On the average, one earthquake of such size occurs somewhere in the world each year. Magnitude measures the energy released at the source of the earthquake as determined from measurements on seismographs. An earthquake has one magnitude. The magnitude scale most commonly in use now is called the moment magnitude scale. Moment is a physical quantity proportional to the slip on the fault times the area of the fault surface that slips; it is related to the total energy released in the EQ. The moment magnitude p...

MySQL Database Table Prefix Explained: How to Change It in Minutes

How to Change a MySQL Database’s Table Prefix: A Step-by-Step Guide Introduction Changing the table prefix of a MySQL database is a common task for enhancing security or reorganizing database structures. This guide walks you through the process step by step, ensuring clarity and efficiency. Whether you're a developer or a site administrator, these instructions will help you tackle the task with confidence. Why Change Your Table Prefix? Enhanced Security : Default table prefixes, like wp_ in WordPress, are often targeted by attackers. Changing them can reduce vulnerabilities. Customization : A new prefix makes your database easier to identify in complex environments. Avoid Conflicts : Helps prevent issues when importing databases into shared environments. Changing a database table prefix is easy and here’s the simple step-by-step guide! For WordPress installations, it’s essential! How to change a prefix 1. In your text editor, change database_name, old_prefix_ and new_prefix_ to ...

Selecting COUNT from MySQL table by first letter of a column

Method 1: SELECT count(*) total,     SUM(case when trim(last_name) like 'a%' then 1 else 0 end) A,     SUM(case when trim(last_name) like 'b%' then 1 else 0 end) B,     SUM(case when trim(last_name) like 'c%' then 1 else 0 end) C,     SUM(case when trim(last_name) like 'd%' then 1 else 0 end) D,     SUM(case when trim(last_name) like 'e%' then 1 else 0 end) E,     SUM(case when trim(last_name) like 'f%' then 1 else 0 end) F,     SUM(case when trim(last_name) like 'g%' then 1 else 0 end) G,     SUM(case when trim(last_name) like 'h%' then 1 else 0 end) H,     SUM(case when trim(last_name) like 'i%' then 1 else 0 end) I,     SUM(case when trim(last_name) like 'j%' then 1 else 0 end) J,     SUM(case when trim(last_name) like 'k%' then 1 else 0 end) K,     SUM(case when trim(last_name) like 'l%' then 1 else 0 end) L,     SUM(case when trim(last...

Mysql regexp to allow numbers and '+'

First, use  NOT REGEXP  instead of  !=1 . To allow  +  at the start optionally, use  ^\\+? . Since  +  is a special character in regular expressions, it must be escaped with a backslash (which must be escaped with another backslash). You then need one or more digits ( [0-9]+ ), up to the end of the string  $ . $query="UPDATE table SET phone='NULL' WHERE phone NOT REGEXP '^\+?[0-9]+$'"; This will match anything that doesn't begin optionally with  + , followed by digits only. If you also need to permit hyphens and dots in the phone number, add them into the  []  character class: '^\\+?[0-9.-]+$'

Document Expired or Webpage has expired on back button

If you have a dinamic website and want to allow your visitors to use the back button after they sent a form with the post method, the best combination I found was: <?php header("Expires: Sat, 01 Jan 2000 00:00:00 GMT"); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Cache-Control: post-check=0, pre-check=0",false); session_cache_limiter("must-revalidate"); // and after you start the sessionsession_start(); ?> I try some combinations using header("Cache-Control: no-cache, must-revalidate"), but when clicking the back button, the last changes in the form back to their previous states. The combination above works fine with IE 6.x. I didn't test this with other browsers. When I try something like session_cache_limiter("nocache, must-revalidate") it doesn't work. The page only updates when I used the browser's refresh button. In dynamic web sites this is not g...

PHP String Splitting: Explode by Multiple Spaces or Tabs Easily

How can I explode a string by one or more spaces or tabs? To explode a string by one or more spaces or tabs in PHP, you can use preg_split() instead of explode(). The preg_split() function allows for splitting strings using regular expressions, making it perfect for handling multiple spaces or tabs as delimiters. Example Code Here’s how you can achieve it: <?php // Input string with multiple spaces and tabs $input = "This is\tan example string"; // Use preg_split with a regex for spaces and tabs $result = preg_split('/[\s]+/', $input); // Output the result print_r($result); ?> Explanation: preg_split(): This function splits a string based on a pattern (regular expression).   Regular Expression /[\s]+/ : \s matches any whitespace character, including spaces, tabs, and newlines. [ ]+ ensures one or more consecutive whitespace characters are treated as a single delimiter. Result: The string is split into an array based on spaces or tabs, regardless o...

CodeIgniter Interview Prep: 50 Must-Know Questions and Answers

Master CodeIgniter with These Top 50 Interview Questions and Answers 1) Explain what is CodeIgniter? Codeigniter is an open source framework for web application. It is used to develop websites on PHP. It is loosely based on MVC pattern, and it is easy to use compare to other PHP framework. 2) Explain what are hooks in CodeIgniter? Codeigniter’s hooks feature provides a way to change the inner working of the framework without hacking the core files. In other word, hooks allow you to execute a script with a particular path within the Codeigniter. Usually, it is defined in application/config/hooks.php file. The hooks feature can be globally enabled/disabled by setting the following item in the application/config/config.php file: $config[‘enablehooks’] = TRUE; 3) Explain how you will load or add a model in CodeIgniter? Within your controller functions, models will typically be loaded; you will use the function $this->load->model (‘Model_Name’); 4) Explain what helpers in...

Adjusting PHP Session Timeout: A Step-by-Step Guide

How to change the session timeout in PHP Changing the session timeout in PHP can be done by adjusting the session's lifetime settings. PHP sessions rely on two parameters to manage their timeout: the session.gc_maxlifetime directive and the cookie_lifetime setting. Here’s how you can do it: Step 1: Modify session.gc_maxlifetime The session.gc_maxlifetime directive specifies the maximum lifetime of session data, in seconds, before it’s considered garbage and removed by the garbage collector. Add the following code to your PHP script: PHP: ini_set('session.gc_maxlifetime', 3600); // 3600 seconds = 1 hour Step 2: Adjust Session Cookie Lifetime To ensure the session persists in the browser for the desired duration, you should also set the session.cookie_lifetime value. PHP: ini_set('session.cookie_lifetime', 3600); // 3600 seconds = 1 hour Step 3: Start the Session Ensure you call session_start() after these settings: PHP: ini_set('session.gc_maxlifetime',...