Dynamic Night Mode with PHP
1062   1  

Dynamic Night Mode with PHP

  11 Nov 2017
  Coding Category
Dynamic Night Mode with PHP

  25% more discounted by using the Giliapps as code in HostGator

If your users don't like sleeping :-) you can redesign your website to look better in the midnight. You can set it with Static CSS and let them to active night mode by a button, or set it with Dynamic CSS and PHP or JS. We work with PHP and CSS.

1. In most PHP websites, there is a config.php file that call everytime needed. Set your Timezone in that like this:

mysqli_query($db,"SET time_zone = '-05:00'");

2. If you use a footer.php that call in bottom of every pages, add this to that, or just add this to bottom of your pages:

$lt = 0;

    if ((int)date('G') <= 8 ) {

        $lt = 0.2 - ((int)date('G') / 40);

    } elseif ((int)date('G') >= 19) {

        $lt = (int)date('G') / 115;


    echo '<div id="foreground" style="z-index: 10001; filter: sepia(60%) brightness(90%); -webkit-filter: sepia(60%) brightness(90%); position:absolute; height:100%; width:100%; background-color:rgba(150, 50, 50, ' . $lt . '); pointer-events:none;"></div>';

3. I see Alpha in rgba, don't work correctly in some devices. For example alpha = 0.002 act same as alpha = 0.1. I will happy to see your suggestions to improve this code.

Author: Ismael Azaran

Do you like it? Share it with your friends.