Weather station scripts - Environment Canada

They're free, but use at your own risk

The scripts referenced here are used in the operation of this weather station, and may be freely copied and used to support your station. Please note that you use these scripts at your own risk. No warranty is expressed or implied. I accept no liability for any damages that may ensue from their use.
You will need to configure them for your own particular weather station website.
RSS feed for Scripts Updates A RSS Feed is available to help keep you informed on updates to the scripts.

Many of these scripts are now available on GitHub at

Buy Me A Coffee If you find one or more of the scripts useful to you, please consider making a donation to help offset the routine expenses of operation of this website.
Thanks for your kind support!

A Version History is available -- check back from time to time to see if there are updates to scripts you have downloaded earlier. Announcements of version updates and new scripts are made on and Weather-Watch forums and saratogaWXPHP Twitter account as they become available.

Note: Twitter widget has been disabled 3-Jul-2023 since it no longer displays the recent update Tweets.

This page was updated Thursday, 09-Feb-2023 1:47 PM

PHP Scripts (run on webserver)


Environment Canada lightning script (for

This script will read the HTML from the Environment Canada Lightning Danger Map page (cached) and download/cache the lightning map images as .png files on your website. Since the EC uses lightning graphic names with embedded timestamps, this script offers one of the few ways that weather enthusiasts can include EC lightning map images in their own websites.

The ec-lightning.php script uses a subdirectory (./radar/ default) to store the contents of the EC lightning HTML pages and the current lightning graphics. For proper operation of the script, you need to ensure that the cache directory is writable by PHP scripts. A simple test script is included to check this (ec-lightning-cachetest.php).

The script will load the HTML page from the EC website, cache it, and parse the contents for the lightning graphic images available, then download, resize and cache the images in ./radar/lightning-AAA-N.png files (AAA=siteid, N=0 (oldest) to 6 (most recent). Then the script will generate HTML and JavaScript to display the graphics from the cache and the associated date stamps for the lightning map images. The script generates uniquely named JavaScript functions/variables to allow you to embed more than one Lightning set on a page (as shown below). A smaller (1/4 size) image is also available of the most recent lightning map image as ./radar/lightning-AAA-sm.png. The following parameters are available on the ec-lightning.php script:

If present, the script will load lightning map images from the 'AAA' lightning site. The available lightning maps are:
id=NAT - National lightning (script default $lightningID)
id=PAC - Pacific region lightning
id=WRN - Prairies region lightning
id=ONT - Ontario region lightning
id=QUE - Quebec region lightning
id=ATL - Atlantic region lightning
(Default) Text is in English..
Text is in French .
(default)--Start the JavaScript animation when page is loaded.
Don't start the animation when the page is loaded. Viewer must press play-stop button to start animation.
Return a 1/4 size static image of the latest lightning selected.
This is for use in an <img> statement on your page like this:
<img src=""
width="290" height="240" alt="lightning" title="lightning" />
See example 1 below for usage.
Note: the small lightning map images are width="290" and vary in height.

For webmaster help with debugging the setup/configuration of the script, the following parameters may also be used:

Forces refresh of EC lightning page and lightning map images .

Settings inside the script

If you create a writable /lightning subdirectory in the document root of your webserver, then the only settings you should change are $siteID and $defaultLang.

// Settings:
// --------- start of settings ----------
//  Go to
//  Click on the desired area page.
//  You should see a lightning page with an url like
//  copy the three letter area id=XXX into $lightningID = 'XXX'; below
$lightningID = 'NAT';      // set to default Site for lightning (same as id=xxx on EC website)
//                         // available sites: NAT ARC PAC WRN ONT QUE ATL
$defaultLang = 'en';  // set to 'fr' for french default language
//                    // set to 'en' for english default language
$lightningCacheName = 'ec-lightning.txt';     // note: will be changed to -en.txt or 
//                                  -fr.txt depending on language choice and stored in $lightningDir
$lightningDir = './radar/';  // directory for storing lightning-XXX-0.png to lightning-XXX-6.png images
//                             note: relative to document root.
$lightningWidth = 620;  // width of images to output in pixels.  default=620
$refetchSeconds = 300;  // look for new images from EC every 5 minutes (300 seconds)
//                      NOTE: EC may take up to 20 minutes to publish new images    
$noLightningMinutes = 25;   // minutes to wait before declaring the image site as 'N/O -not operational'
$aniSec = 1; // number of seconds between animations
$charsetOutput = 'ISO-8859-1';   // default character encoding of output
// ---------- end of settings -----------

Example 1 - Current default lightning small image

<img src="" width="290" height="240"
alt="Latest Canada lightning from Environment Canada"
title="Latest Canada lightning from Environment Canada" />

Results in:

Latest Canada lightning from Environment Canada

Example 2 - Canada National Lightning in French

  $doInclude = true;
  $doPrint = true;
  $doAutoPlay = true;
  $doLang = 'fr';

Results in a National lightning map with animation (in French):

La carte canadienne du risque de foudre (CCRF) indique les secteurs les plus susceptibles d'être frappés par la foudre au cours des 10 prochaines minutes. Les heures sont indiquées en Temps universel coordonné (UTC). L'intervalle entre les cartes est 10 minutes. Veuillez rafraichir votre navigateur (ou actualiser la page) pour avoir la carte la plus récente. En savoir plus la carte canadienne du risque de foudre.

Carte canadienne du risque de foudre - Canada - #7 @ 21:20 UTC, 7/7
Carte canadienne du risque de foudre  - Canada - Environment Canada

red dot
  • Il y a des éclairs dans les zones en rouge. Vous êtes en danger immédiat si vous êtes à l'extérieur.
  • Réfugiez-vous en lieu sûr, soit dans un immeuble comportant de la tuyauterie et du câblage électrique, ou dans un véhicule entièrement métallique
  • Restez à l'abri pendant 30 minutes après le dernier grondement de tonnerre

Carte canadienne du risque de foudre - Canada - Environnement Canada

Environment Canada Lightning PHP script [V1.05 - 09-Feb-2023] : demo [ see version history ]

Installation Instructions

  1. Download ec-lightning-cachetest.php script from here and upload to your website (in your document root directory).
  2. If you are NOT already using the ec-radar.php script, then create a new ./radar/ directory on the webserver one directory below where you placed the script.
  3. Upload ec-lightning-cachetest.php script to the chosen directory from step 1 and run the program from your browser.
    If the ec-lightning-cachetest.php reports success in writing the file, finding the needed legendLightning.png and that GD is installed, then proceed to step 4.
    If you have error messages appearing, then you'll have to fix the problem on your webserver (by changing the permissions on the ./radar/ directory to 777 on Linux/Unix systems, or allowing 'all' to read/write/create on IIS system). The ec-lightning.php program requires the use of cache files, so you'll have to get a clean run on ec-lightning-cachetest.php to have ec-lightning.php run successfully.
  4. Download ec-lightning.php from here, and change other settings ($lightningID) as you like.
  5. Upload ec-lightning.php to the same directory that successfully ran ec-lightning-cachetest.php.
  6. View ec-lightning.php with your browser. You should see the animation of your selected ($lightningID) lightning map.
  7. Install links in your other webpages for the lightning map images you desire.

Note: this script is included with the AJAX/PHP Base-Canada template sets (English and bilingual English/French).