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.
http://linux971.blog92.fc2.com/blog-category-2.html
I'll explain why this is so later. (I just don't know right now.)
Continue.
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['error']=array();?>
<?php session_destroy(); ?>