News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Undefined variable $sid in Subs.php and QueryString.php after Upgrade

Started by MobileCS, June 24, 2025, 02:44:48 PM

Previous topic - Next topic

MobileCS

After upgrading to SMF 2.1.5, I see a whole bunch of these errors in my admin panel:

(I use queryless urls)

Undefined variable $sid - QueryString.php (Line 699)

return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . $sid . (isset($m[2]) ? $m[2] : "") . '"';
Undefined variable $sid - Subs.php (Line 4151)

return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . $sid . (isset($m[2]) ? "$m[2]" : "");
I'm not sure why I am getting these, as this line is present in both files:

$sid = defined('SID') ? @constant('SID') : null;
Edit:

It doesn't like these urls in QueryString:
https://www.example.com/forum/index.php?PHPSESSID=993acd181ae6ca39660302e490e4541b
And these in subs.php
https://www.example.com/forum/index.php?msg=239564

MobileCS

This is weird, my package manager shows this:



Also, all my mods show as uninstalled ("Install" buttons are showing beside all of them)

I believe they are installed, but just disabled. Any way to fix that?

 

Illori


MobileCS

Ok even when I mark it as installed, it's not working.

It is ok to reinstall them? No hooks are showing either in "Intergration Hooks" section either.


Also, any idea how to take care of those "Undefined variable $sid" errors? I'm getting about 500 of those errors every 30 minutes.

Doug Heffernan

Quote from: MobileCS on June 24, 2025, 03:51:52 PMIt is ok to reinstall them? No hooks are showing either in "Intergration Hooks" section either.

Yes, you can re-install all mods provided that they are compatible with the 2.1. branch. I am mentioning this because you didn't say what version you upgraded from. If you upgraded from 2.0. branch then most mods aren't compatible with the current smf version.

MobileCS

I upgraded from 2.1.4 to 2.1.5 - most of them are hooks only.


Sir Osis of Liver

Looking at your previous topic, I think you may have buggered things up by running upgrade.php without uploading the package files.  If you had installed the patch in package manager you wouldn't be having problems, but you apparently did a little of both and may not have the updated files installed.
When in Emor, do as the Snamors.
                              - D. Lister

MobileCS

In the admin panel there was a link to upgrade the forum, I did click on that, and then the "Install Now" button.

After that, it was complaining that I did not run upgrade.php - then I downloaded the large upgrade package for that file and then ran it (mistake #1 apparently).

I now have two versions of "SMF 2.1.5 Update" in package manager that show:



The bottom of my forum shows version 2.1.5.

Where do I go from here?

shawnb61

If you are already on 2.1.5, due to the upgrade, you do not need to run the 2.1.5 patches.  I would just delete those.  (Not sure how you got 2 there, maybe one's left over from the beta?  But either way, if you're already on 2.1.5, just delete them, you cannot install them.)   

What version of PHP are you running?
A question worth asking is born in experience & driven by necessity. - Fripp

Sir Osis of Liver

Package manager shouldn't have asked you to run upgrade.php, the patch updates files and database (if there are any changes).  I'm not seeing the 2.1.5 patch in 2.1.4 package manager, and you shouldn't need to emulate 2.1.4 to install it even if you did.  You should have at least one, and possibly two backups in /Packages/backups that are from before you installed the patch.  You can d/l, unzip, upload to forum root the earliest one, that will restore files to 2.1.4, but it doesn't restore the database.  If you've damaged the database, you'll have to restore your most recent backup.

Always a bad idea to install an update immediately after release. :P

When in Emor, do as the Snamors.
                              - D. Lister

Sir Osis of Liver

Had to run 'Fetch Simple Machines files' scheduled task, now I see it.  2.1.5 patch installed without errors in 2.1.4 core install and custom theme.  Not logging any errors.
When in Emor, do as the Snamors.
                              - D. Lister

shawnb61

With regards to the "Undefined variable $sid", I think I know what's going on here.  Pretty sure it's a bug, a variant of https://github.com/SimpleMachines/SMF/issues/8393.

I believe what's going on is this error is logged when (a) queryless URLs are enabled, and (b) a user with cookies disabled navigates the site.  Oddly, the user isn't affected, but these errors get logged in the background.  So they're harmless but annoying & numerous when these conditions are met...

I believe the fix is to tweak the function definition a few lines before the line that is erroring out. 

Replace:
function($m)
With:
function($m) use ($sid)
Let us know if that works.
A question worth asking is born in experience & driven by necessity. - Fripp

shawnb61

A question worth asking is born in experience & driven by necessity. - Fripp

MobileCS

Quote from: Sir Osis of Liver on June 24, 2025, 05:16:35 PMLooking at your previous topic, I think you may have buggered things up by running upgrade.php without uploading the package files.  If you had installed the patch in package manager you wouldn't be having problems, but you apparently did a little of both and may not have the updated files installed.

The patch was installed via the package manager. The only thing I did beside that was grab upgrade.php from the large upgrade and ran it.


Quote from: shawnb61 on June 24, 2025, 05:49:23 PMWhat version of PHP are you running?

I'm currently on PHP 8.3


Quote from: shawnb61 on June 24, 2025, 06:37:07 PMWith regards to the "Undefined variable $sid", I think I know what's going on here.

I believe the fix is to tweak the function definition a few lines before the line that is erroring out. 

Replace:
                function($m)
With:
                function($m) use ($sid)
Let us know if that works.

That fixed the $sid errors in QueryString.php, but I still have that error in Subs.php on line 4151

        if (isset($sid) && $sid != '')
            $setLocation = preg_replace_callback(
                '~^' . preg_quote($scripturl, '~') . '\?(?:' . $sid . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
                function($m) use ($scripturl)
                {
This line here --->      return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . $sid . (isset($m[2]) ? "$m[2]" : "");
                },
                $setLocation
            );

Edit:
I changed function($m) use ($scripturl) to function($m) use ($scriptur, $sid) and seems to have solved the issue.

I'm assuming that's the correct fix?

shawnb61

Quote from: MobileCS on June 24, 2025, 09:03:36 PMThat fixed the $sid errors in QueryString.php, but I still have that error in Subs.php on line 4151

Ah, sorry, missed that.  A similar change needs to be made a couple lines above that:
                function($m) use ($scripturl)Needs to become:
                function($m) use ($scripturl, $sid)

I suspect running upgrade.php clobbered the package manager info about your 2.1.5 patch. 

It's possible the fix_packages tool over on Downloads may help you flag one as being installed???  I'm not sure that would buy you anything.  Personally, at this point, I'd just delete those packages that erroneously think they're not installed & call it done.

A question worth asking is born in experience & driven by necessity. - Fripp

MobileCS

Quote from: Sir Osis of Liver on June 24, 2025, 05:54:45 PMYou should have at least one, and possibly two backups in /Packages/backups that are from before you installed the patch.

I do see 2025-06-24_before_smf_2-1-5_patch_1.tar.gz in the /Packages/backups dir. I'm hesitant to revert, as I believe the update really happened. I see a lot of files in the /forum directory were modified with todays date.

The only issue I had is seeing this message after it completed:

SMF file version (2.1.4) does not match SMF database version (2.1.5).
Run the SMF upgrader to fix this.

Since I grabbed the upgrade.php file (and the related sql files) from 2.1.5 large upgrade zip and ran it, did it not upgrade the database to 2.1.5?

The message went away after I ran it.

shawnb61

Since you are on 2.1.5 now, I suggest leaving things alone.

The above message indicates that the 2.1.5 patch did not complete properly.  At the time you saw that message, you still had some 2.1.4 code installed somehow.

It may help to run the version check in the admin console, to confirm you're really on 2.1.5.
A question worth asking is born in experience & driven by necessity. - Fripp

shawnb61

As ever, if you make a tweak like the above in your code, you will need to revert it before applying the next patch...

I should have mentioned this above.
A question worth asking is born in experience & driven by necessity. - Fripp

MobileCS

Here is what the versions page shows:

SMF File        Your version    Current version
SMF Package        SMF 2.1.5            SMF 2.1.5
Sources             2.1.5            2.1.5
Default Templates  2.1.5            2.1.5
Language Files        2.0.18            2.1.5
Background Tasks    2.1.5            2.1.5

The language files version an issue?

I think I know what happened with the update yesterday.

I have OPcache enabled in PHP, but also have "opcache.validate_timestamps=0" set so it never checks for file changes. It's supposed to be great for performance on production sites, as it doesn't have to keep doing tons of stat calls to see if files have changed or not.

So I'm assuming after the update, the forum still was running all the old files and that's where things messed up. In that confusion, I completely forgot about the OPcache setting.

I don't have OPCache or SEF URL's enabled on my test forum, so that's why I never saw any issues until I installed it in on my live server.

Going forward, I will disable OPcache during updates and hopefully that will solve the issue.

Optionally, you may want to consider doing a check for OPcache after a package upgrade and clear the cache if it's enabled. It's pretty simple to do, and may save someone else from dealing with this issue.

if ( function_exists('opcache_get_status') ) {
    $status = opcache_get_status();
    if ( $status['opcache_enabled'] == 1 ) {
        opcache_reset();
    }
}

As for my forum, it up and running now without any issues. I used fix_packages.php and marked my addons as installed, then uninstalled and reinstalled them. All but 2 were hooks only, and the ones that weren't only had a couple lines of code, which I confirmed had nothing to do with the 2.1.5 updates.

Advertisement: