I've been having this problem when trying to access my server. When I open the server through the Forge version, the server loads normally, but if I try to launch it through the optifine version, an error message (attached) says that Forge is required to join the server to run the mods, despite Optifine also running through Forge. I'm using the 40.1.76 version of 1.18.2 forge, the 1.18.2 HD U H7 version of optifine and have updated my JDK but it still shows the error message.
EDIT: I SOLVED THE PROBLEM. turns out, I hadn't put optifine in my mods folder for Forge, so now I have optifine up and running through my Forge client!