Home > front end >  Why does a .php file's content get deleted eventually?
Why does a .php file's content get deleted eventually?

Time:08-10

The question might sound silly, but here's the case:

I have a project running on a live server (using cPanel) and it has two parts: one for the visitors and one for the admins. Both of these parts are stored in the same directory, but the full admin with all of it's files is placed in a sub-directory.

Everything works smoothly, but sometimes (like once a week) a specific file's content (menus.php) gets deleted. The file itself doesn't get deleted, but all the code from it disappears and I'm left with an empty menus.php in the admin sub-directory.

I've been searching the sourcecode for hours but don't see any signs of anything that should cause this issue.

Has anyone ran into something like this before?

I'm grateful for any ideas or suggestions here.

Thank you so much in advance!

CodePudding user response:

I would search your codebase for file_put_contents() or fopen() and see if you're accidentally writing to your own scripts somewhere. If it's not that, you could try renaming and relocating the menu scripts elsewhere to see if an external process is the culprit.

CodePudding user response:

Probably this is some sort of automated job running somewhere, once a week, that uploads an empty version of that file to your site.

As a quick fix you can try changing the permissions on the file in question. In cpanel's file manager,

  • right click on the file and choose Change Permissions.
  • make sure none of the boxes for Write permission are checked.
  • click the Change Permissions box.

Don't forget to change the permissions back before you upload a new copy.

You could also try changing the ftp password for your cpanel account. That will stop a rogue automated ftp upload.

  •  Tags:  
  • php
  • Related