Tuesday, October 20, 2020

Interesting feature in PHP where if you do a $_GET on a variable that has a zero (0) value the result is empty and not zero.

Today I noticed a divide by zero error in the error log for my Voltage Drop Calculator. That didn't make sense to me because I test to see if a value is being divided by zero before doing a divide. That's pretty basic computer programming logic.

 However the test to see if the variable was zero wasn't working. If I put a number in the Cross Section field the calculation works perfectly. When I put a zero in the Cross Section field the zero was effectively being ignored. This didn't make sense to me.

I'll admit this is a limitation of my knowledge of PHP. Each programming language has it's quirks (features) and this is one of PHP's that I missed and to be fair, it was bad programming on my part.

When receiving the variable in the URL I would then use if ( $_GET['variable']) to test to see if the variable had a value. What I didn't know was a zero value is treated as being empty. Thus when I later tested the value of the variable against zero the test was false and a divide by zero would occur because the calculation would be performed.

What I really should have done (and have now done) in the code is to test if the variable was set. I've now updated the code to be, if ( isset($_GET['variable']) ) and the code works as it should.

I'm sure if I've made this simple mistake others may also fall into this trap. Hopefully others can learn from my mistake.

Kelvin Eldridge
www.OnlineConnections.com.au



Friday, October 2, 2020

Recovering files from a corrupted SD card and an SD card Windows suggested needed formatting. The SD cards were used in a Canon camera.

A family member gave me a couple of SD cards which had become corrupted. One was not able to be read, but the other one had three folders and one very big file which had non-English characters in the file name. A good sign of corruption.

The first SD card gave the following message.

The second SD card's file directory looked like the following.



Over the years I tried a few programs so like most people I tend to go back to what I know that what's worked in the past, plus I tried Microsoft's new Windows File Recovery tool. You would think Microsoft could produce the best tools, but in this case the Windows File Recovery tool was a waste of time.

I also tried a product called RECUVA, but the product was not able to recover anything.

Another company that has produced results in the past is called EaseUS and they have a product called EaseUS Partition Master, but that product didn't help. However in the menu of this product I was able to download their EaseUS Data Recovery Wizard and with this product I was able to find 751 files I could recover from the SD card with the corruption.

I started the recovery process for a subset of the files as the website said the free version can recover up to 2GB of data. Whilst true I found it would only recover 500MB. I then checked the website again and found the 2GB feature is unlocked if you share a post on Facebook or Twitter. For a moment I thought I perhaps should have tried their free trial on their pro version. I decided to test the free trial. No help as it only scans and displays the files found. No ability to recover.

In total there was around 3GB of data that could be recovered. With a 2GB limit it meant I need to find out more information about what the family member already had and what they didn't have. It turned out they didn't need the RAW files taken by the camera. Once that information was available I was able to complete the recovery of the photos.

Full credit to EaseUS for providing the ability to recover the person's photos for them.

Now for the SD card that just gave the message it needed to be formatted, I decided to search for another program since EaseUS couldn't help. I found an open source program called PhotoRec and tried the program on both SD cards. PhotoRec was able to recover most of the photos from the corrupted SD card, and also recovered a large number of files for the SD card that gave the prompt the card needed to be formatted. The only real issue is PhotoRec does not use the original file names, but instead gives them the next sequential number. Although to be fair, having photos even if the file names don't match isn't as big an issue as not photos at all.

Both EaseUS and PhotoRec produced results, although you can never be sure of what files were missed. EaseUS was able to identify three video files that PhotoRec did not detect.

One tip I'd like to share is if your SD card gives you issues, put it aside immediately and then use a recovery program. Don't keep using the SD card otherwise files may not be able to be recovered.

Another tip is don't use your computer to format the SD cards or delete or edit files on the SD card. To use and work on the photo files copy the files to your computer. To format the card or delete files use the camera. There's a feeling that incompatibility between devices may lead to corruption.

Finally don't just keep taking photos and videos on the SD card and think they're safe. Everyone now and then take a backup copy of the SD card. One day you'll be glad you did.

Kelvin Eldridge
www.OnlineConnections.com.au