WXforum.net

Web Weather => Weather Website PHP/AJAX scripting => Topic started by: K6GKM on January 04, 2022, 03:26:47 PM

Title: PHP "Undefined constant" error - How to correct?
Post by: K6GKM on January 04, 2022, 03:26:47 PM
Hello Everyone,

Doing a little website maintenance today, and I checked my php error_log file for the first time in a long time.  I have a script throwing a series of errors out every time it's executed, and I was hoping the brains in this forum could help me correct it.  Here's the error:

Code: [Select]
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 356
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 436
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 437
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 438
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 439
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 440
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 441
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 450
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 451
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 452
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 453
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 454
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 455
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 464
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 465
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 466
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 467
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 468
[04-Jan-2022 12:15:01 America/Los_Angeles] PHP Warning:  Use of undefined constant imagesDir - assumed 'imagesDir' (this will throw an Error in a future version of PHP) in ***REDACTED***/wxaqirss.php on line 469

I've loaded fresh copies of the wxaqirss.php package obtained from the legacy scripts page on Mr. Ken True's website, but I just can't seem to make this pesky error go away.  Line 45 sets $imagesDir to a directory of your choice, but the comments say it may or may not be required.  I've tried uncommenting that line, but I still get the error.  The script in question (located at CamWX.com/wxaqirss.php (http://CamWX.com/wxaqurss.php)) is attached here (in txt format).  Could anyone offer any insight?

Many Thanks!
Title: Re: PHP "Undefined constant" error - How to correct?
Post by: saratogaWX on January 04, 2022, 03:32:56 PM
Ahh... the code has
Code: [Select]
// Images Directory (may not be needed, remove the // if needed)
// $imagesDir = "./ajax-images";
but, the comment is not quite right.. it is needed.  So change it to
Code: [Select]
// Images Directory
 $imagesDir = "./ajax-images";
Title: Re: PHP "Undefined constant" error - How to correct?
Post by: K6GKM on January 04, 2022, 03:37:42 PM
Hi Ken,

Thanks so much for the lightning quick reply.  I've tried uncommenting that line, but the problem still persists.   :-k 
Title: Re: PHP "Undefined constant" error - How to correct?
Post by: saratogaWX on January 04, 2022, 03:46:11 PM
If you're still getting errata, try changing all the
Code: [Select]
<?php print ${imagesDir}?> to
Code: [Select]
<?php print $imagesDir?>
Title: Re: PHP "Undefined constant" error - How to correct?
Post by: K6GKM on January 04, 2022, 06:33:32 PM
Thank you, Ken.  After making the changes to the print statements, the errors cleared up.    8-)

Thanks again, and take care.