Friday, April 21, 2017

Best way to store HTML code in MYSQL and echo from mysql PHP

Best way to store HTML code in MYSQL database and echo/display from mysql database to browser using PHP.

htmlentities(HTML, ENT_QUOTES, "UTF-8") function — Convert all applicable characters to HTML entities.

This function Returns the encoded string. If the input string contains an invalid code unit sequence within the given encoding an empty string will be returned, unless either the ENT_IGNORE or ENT_SUBSTITUTE flags are set.

$str "A 'quote' is <b>bold</b>";

echo $str = htmlentities($strENT_QUOTES);// Outputs: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;

If you want to decode instead (the reverse) you can use html_entity_decode().

echo html_entity_decode($str);
// A 'quote' is <b>bold</b>

Tuesday, April 18, 2017

Website Document Root outside public_html for addon/sub domains

When adding an Addon OR Sub domain, the default DocumentRoot on cPanel servers is /home/user/public_html/addon.com.

What if you want to set the DocumentRoot outside public_html ? You can when adding Addon OR sub domain. But, the system WHM won’t allow it. To enable this feature, you need to contact your web hosting provider. Not all web hosts provide this feature. If you have a VPS hosting OR dedicated server, login to your server’s WHM as root. Access option Server Configuration >> Tweak Settings. Look for Restrict document roots to public_html 


This setting prevents the creation of addon domains and subdomains outside of a cPanel user's primary domain's document root (the public_html directory within the user's /home directory).

 For example, if you enable this setting and then create the example.com addon domain, the system creates the /home/username/public_html/example.com directory rather than the /home/username/example.com directory.

This setting defaults to On. Turn it off. Now you can make subdomain's document root outside of public_html folder.

Tuesday, April 11, 2017

Display numbers with ordinal suffix/position in PHP

I want to display numbers/any position like merit position as follows
  • 1 as 1st,
  • 2 as 2nd,
  • 3 as 3rd
  • 21 as 21st
  • ...,
  • 150 as 150th.
As a function:
function ordinal_position($number) {
    $ends = array('th','st','nd','rd','th','th','th','th','th','th');
    if ((($number % 100) >= 11) && (($number%100) <= 13))
        return $number. 'th';
    else
        return $number. $ends[$number % 10];
}
//Example Usage
echo ordinal_position(121);
// show 121st


Incompatible with sql_mode=only_full_group_by Permanent solution


If a query has aggregate functions and no GROUP BY clause, it cannot have nonaggregated columns in the 

select list, HAVING condition, or ORDER BY list with ONLY_FULL_GROUP_BY enabled.

Some people try this for disable it but it's not good at all.
This is not good.
SET sql_mode = ''
Better solution is blew code.

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
The permanent  solution

We open the configuration file we decided on before (/etc/mysql/my.cnf) and add the following line into the [mysqld]section


sql_mode = "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Save, exit, and restart MySQL

Wednesday, April 5, 2017

Site show suspended page but not in WHM suspended list

I've a website which was hosted another server and the site was suspended. After requesting that hosting provider the site was unsuspend and then i transefer the site using whm transfer tool. But after transfer the site was still showing suspended.

I've checked in WHM but in there the site was not in suspended list.

1. First please try re-suspending and then unsuspend the account through WHM. It should be under the "Account Functions"  tab submenu Manage Account Suspension.

2. If the first method doesn't working. then login WHM-->Account Information-->List Accounts-->search the account and click on cpanel icon to login cpanel of that site.
Then open the file manager and open the folder "cache" and delete all the cache files.

Now the site works.

Total Pageviews