Wxclimate.php in php 8

Trying to get this to work in php 8… Once i switch from 7 to 8 it instantly dies. I think I’m getting 404 errors on trying to open some files, so something changed in how php 8 reads things…

wxclimate.txt (8.8 KB)

Of course things have changed with PHP 8.

Why don’t you take Ken’s advice and run with the 6.95h version of the alternative dashboard scripts instead of your hybrid.

His comment was about cloudheight.php not this… I’ve gotten the rest of my files working so far… thanks.

Not sure about that :wink:

considering he posted in the thread about cloudbase and no one has posted in the wxclimate thread… …

you want to keep going??

Anyway, back to weather scripts… anyone have any solutions for php 8?

Simple debugging tips… check the error_log for your site first. It likely has any PHP errata listed.

If that wasn’t revelatory, then add

error_reporting(E_ALL);
ini_set('display_errors','1');

after the starting <?php on the page. Then all errors will show inline in the page being debugged.

Some functions have been deprecated in PHP 8. Notably,
split() needs to use explode() instead.
‘naked’ constants (like $a[WHAT]) have to be quoted (like $a['WHAT'])
strings/arrays/numbers need to match in variable’s usage (otherwise conversion errors
will display) e.g. initializing a variable as a string $var = ''; then trying to use it as an array $var[0] = 'something'; will result in errors.
doing a $var++; when there is no prior $var = 0; will result in a Uninitialized variable error.

Hope that helps…

1 Like

thanks… yeah im getting a 404 error and no error is being displayed… so ill keep digging.

Ummm… a 404 error just indicates the page you tried to load isn’t present on the website with that name. It has nothing to do with adding the debug enabling code I suggested.

Maybe you named the page with upper and lower case characters… on *nix servers, case is important. wxPage.php !== wxpage.php and a 404 can result if the incorrect name is used for the request in your browser.

i get what a 404 is. its having a hard time putting together the names in php 8

this is in php 8
view-source:Frogville´s Weather Service - General Climate Data

<? echo "$file"; ?> </td></tr></table> <? $date = $_GET['date']; if (!isset($date)) { $date = "climatedataout"; } $breport = "./".$date.".html"; $height = "800"; ?> <iframe name="I1" src="[<? echo $breport ?>](view-source:https://frogville.us/%3C?%20echo%20$breport%20?%3E)" marginwidth="0" marginheight="0" height="<? echo $height ?>" width="100%" frameborder="0"> Your browser does not support inline frames or is currently configured not to display inline frames.

$brreport should be a real name… i can show you what it normally looks like in php 7.

Those two characters are the problem.

If you check the html source of your page, you will see a lot of PHP code which is not executed and considered to be some html ? comment by the browser.
When you change those <? to <?php the code will be excuted on your webserver.

The shortcut <? is not valid in PHP 8.2
You have to use <?php

<table><tr><td style="width:100%;">

<?
// Yearly starts
?>

<b>Yearly Reports:</b> 
<form action="" method="get">
<select name="date">

<?

global $datefile3;

#################
# begin settings
# ##############

# be sure to set the two settings variables below

# enter 4 digit year of your oldest report on your server - example: 2006
$startyear = 2011;

# Location of where the data files are located.
# You may need to change this and it must end with a slash.
# ./ is used if the files are in the same folder as your page with the dropdown list
$webdire = './';

#################
# end settings
# ##############

function getmonthfiles3() {
 global $startyear, $webdire;

 # find out how many years do we need to list files for
 $thisyear  = date('Y');
 $year  = date('Y');
 $thismonth  = date('F');
 $yearcount = $thisyear - $startyear;

Sorry, thought it was part of the same distribution. . . my bad :slightly_frowning_face:

that did it!! thanks so much.
now to the next script thats broken in php 8…
wxclimate.txt (8.9 KB)

updated file attached for others to use in php 8