Out of nowhere, I'm redeclaring things I'm not redeclaring.


#1

Literally out of nowhere, I am getting this message for every page on my website including the header file except the header itself.

PHP Fatal error: Cannot redeclare insert() (previously declared in /home/me/public_html/include/functions.php:19) in /home/me/public_html/include/functions.php on line 51

The header file is the only one that has a “require functions.php” and it will load if I request it by itself. Each page is made up of basically five files: scanner.php, which scans for bad bots and whether or not its a mobile device (no includes), the header file which has the functions.php include, the page file which has the content which has include scanner.php and either include header.php or mobile.header.php and the footer which has no includes.

Literally out of nowhere the pages no longer load and I get that error message. I have changed nothing about the files. Line 51 in functions.php is just a bracket, and the lines above and below are whitespace. The insert() function is only declared once and not mentioned again in the entire file.

Just to get things back and running again I remembered a similar problem so I changed the require to “require_once” and all of a sudden things are back to normal. What the hell? I don’t get it. Why the hell was it saying I am redeclaring things I am not? If you add all the files together in one page, insert is only mentioned once, so how in the hell is it being “redeclared”?

Any advice would be appreciated. Thanks.


#2

Are the files on github or similar? Hard to know without looking into it


#3

No they’re on my cPanel account hosting account for my website. I wrote most of the code, and like I said it was working fine yesterday. Made ZERO changes and all of a sudden get this error.


#4

I would make a cursory glance and switch requires and includes to be require_once and include_once to start with.


#5

Code doesn’t just change operation by itself. If someone managed upload a .php script to your site, broke into your hosting control panel login, or the server permissions are not set up correctly (on shared web hosting), someone/bot could have added or altered files. You should have a known good backup stored off-line. You should download the current code and compare it with the last known good backup.

Another possibility is the server configuration has been changed, most likely for the auto_prepend_file setting. Use a phpinfo() statement in a .php script and check what the setting is. It should be empty, for no auto prepend file. If it now shows your header.php file, it’s possible that something (php version change) caused a commented out setting to become active (# are no longer recognized in php7 as comments in the php.ini - don’t know if they are ignored or throw an error.)