Skip to main content

Posts

Height in Feet and Cms using PHP

The following code can be used to generate a Select field as displayed in the image. It is done in core php. <select name="height" required> <option value="">Select</option> <?php for($inches=48;$inches<=78;$inches++) //Change the range in inches as required { $cm=ceil($inches*2.54); $feet=(($inches-($inches % 12))/12)."&rsquo; ".($inches % 12)."&rdquo;"; ?> <option value="<?php echo $cm; ?>"><?php echo $feet.' ('.$cm.' cms)'; ?></option> <?php } ?> </select> Keywords: html form select options convert height length inch cm cms to feet

Connecting to SSH using key file

 If you get the file permission error in windows while connecting to SSH using  ssh -i e:\keyfiles\myserver.key or myserver.pem then Locate file in explorer and right click Go to Properties Go to Security Go to Advanced Disable Inheritence Delete all permissions Add the current user and give Read and Read & Execute permissions DONE

Installing Purchased SSL

After purchasing a certificate credit, you will need to generate the certificate. A csr file and key will be required. These can be generated at  https://csrgenerator.com/ Fill in the information and generate CSR + Key Copy and paste the CSR in the SSL Provider's site and get the cert Paste the cert date and key data in respective boxes of SSL configuration in the domain hosting or load balancer.

CRON Jobs

In Sentora Environment, CRON Jobs can be run using Root Level Crons or Sentora Crons. If it is a system level command like restarting services or backup outside the root, then system level cron should be used. For running php scripts like sending daily summary, mailing database backup, etc then Sentora cron should be used.

Hardening & Crash Protecting CentOS + Sentora Server

It often happens that database or dns of a server fails and the sites hosted in it stop working. A server reboot or a start of the service brings things to normal. This can be stopped by server hardening as attacks are a prime reason for overloading and crashing of services. Hardening is delat in this article. However, services may stop for internal reasons too. So we will add a cron job that will check for service status and start it if it is crashed due to any reason. List all services and their status systemctl list-unit-files (exit by ctrl+c) Common services APACHE - httpd DATABASE - mariadb or mariadb.service DNS - named or named.service service named status Auto Recovery 1. Create a file named.bash #!/bin/bash service=mariadb if (( $(ps -ef | grep -v grep | grep $service | wc -l) != 2 )) then echo $(ps -ef | grep -v grep | grep $service | wc -l) echo "$service is running!!!" #else #systemctl start named.service fi

Installing SSL in a Site in Sentora / Cent OS

In Console yum install certbot python2-certbot-apache mod_ssl openssl (If it shows any error, then  yum install epel-release and run above command again) THIS WAS NOT REQUIRED WHEN I WORKED ON CSMCL.IN. So this step can be dropped. Comment listen 443 to #listen 443 in  /etc/httpd/conf.d/ssl.conf using NANO (Still to figure out if above line is mandatory or not. Will check when installing it in third server) THERE ARE 2 DASHES BEFORE APACHE BELOW. certbot –apache for enabling ssl in all sites on the server certbot –apache –d domain1 –d domain 2 for enabling ssl on selected domains if it fails, use certbot -d domain1 -d domain2  (using -apache causes issue in some systems) Rest is fully automatic Later Check certs certbot certificates One click renew all expiring certs certbot renew /// In case you have to delete a cert certbot revoke -- cert - path / etc / letsencrypt / live / CERTNAME / cert . pem certbot delete --...

Handling the CSS Caching Issue

We web developers often come across a scenario where we make a major change in the CSS values and the site is totally damaged for the viewer due to a broken / cached css. This becomes very crucial when the change involves update of both the css file contents and a change in the structure of the front end. To handle such a scenario, specially when you are expecting to update the css too often, the trick below helps a lot. Instead of calling the css using <link href="/theme/public.css" rel="stylesheet" type="text/css"> write the call in a php file called css.php (You can use any other name and extension) Paste the css call in the php file and modify the name of called css to something unique. I prefer adding a yymmdd or v1,v2 etc <link href="/theme/public-190104.css" rel="stylesheet" type="text/css"> Now include the css.php in the page at the place where you would have called the css. Done. Now whenever you make a c...

PHP7 Compatibility Test in Windows / Wamp

Download php7cc.phar  from  https: //github .com /sstalle/php7cc/releases/download/1 .1.0 /php7cc .phar and save it in the root of wamp. (Where you keep all your projects) Then open the command prompt and proceed as given below. Replace the paths according to your system. You will find a detailed report in the specified report file.

GMail Rejecting IPv6 PTR

In case your postfix is not able to send mails to gmail accounts due to a IPv6 PTR failure, you are adviced to adhere to IPv4 in Postfix. edit  /etc/postfix/main.cf , and set  inet_protocols  to  ipv4 , inet_protocols = ipv4 You should restart postfix.

WhatsApp for Windows stuck in Fullscreen

In case your whatsapp for windows is stuck in fullscreen, close Whatsapp and open the following file. C:\Users\ username \AppData\Roaming\WhatsApp\settings.json where username is your login ID in windows. The file can be opened with Notepad or any text editor. Change "isFullScreen":true to "isFullScreen":false Save the file and start WhatsApp. Now you can change the size of the window. (If required, you can change the size of whatsapp window from the json file too.

Clearing image cache when updated with same name

When we update an image but the name remains the same, the browser keeps on showing the old image. This is very confusing for the admin and annoying too. If we use a decaching code, we end up reloading the image from the server on each visit and thus a lot of bandwidth is wasted. The best solution to this is to use a URL that changes when a image is updated. The best approach to achieve this is appending a dummy part to the image src that changes when the image is updated, and what could be better than the file timestamp !! So instead of <img src="image.jpg" width="200"> use <?php echo '<img src="image.jpg?m=' . filemtime ( 'image.jpg' ) . '" width="200">' ; ?>

Handling MISSING Image in HTML

It often happens that we allow users to upload a profile pic. But all the users do not upload a pic. Thus either we have to copy the same template image for all users or we get a broken image in the page. To fix this, use onerror code. Approach 1 - Hide the image if no image is available. onerror = " this . style . display = 'none' " Approach 2 - Use a template / filler image. onerror = " this . src = 'fallback-img.jpg' "