If you want to move variables to another file, $_SESSION is easy to use.
However! session_start() must be used in all files where it is used.
The following site, which is excellent, made me realize this.
I'll explain why this is so later. （I just don't know right now.)
If the session function is not initialized + deleted at the end of the page, it remains forever.
This is apparently because session functions are stored on the web server.
Therefore, it is necessary to initialize + delete the following to reset it every time because an error may already occur on a page opened suddenly if it is left unattended.
<?php session_destroy(); ?>