Aleksa Ristic Aleksa Ristic - 9 months ago 38
PHP Question

Delete specific line from php file

My site got hacked and at every first line of

file i have line:

<?php $knitglx = '<%G]y6d]281Ld]245]K2
$knitglx=$fmfqhx-1; ?><?php
(it is very long). Since i am using wordpress there are millions of files and it is impossible to open 1 by 1 and delete this line. Is there a way to delete them all at once?

I read something about some
functions but i do not know how to use it. Any help would be okay.

Answer Source

If your site got hacked you REALLY should not try to clean the source code they injected!. It is very likely that you will forget something and you may spread malware or whatever to the visitors of your WordPress site. Also try to figure out why you got hacked and fix the hole.

Make sure to delete all files from the server and change all your passwords (FTP, WordPress, etc. etc.).

Here is what you can do:

1) Contact your provider and ask them to setup the latest clean backup

2) Setup your own latest clean backup

3) If you really have no backup (which is very bad) do the following:

  • Make a fresh installation of WordPress.
  • download your wp-content folder and check this for any malicious code
  • download your database and check for any malicious code
  • place the clean code / database into the WordPress installation

Simple deleting the first line of each file is most probably not enough. However there are solutions to this:

Batch file to delete first 3 lines of a text file

Delete certain lines in a txt file via a batch file

Note: With an IDE like Netbeans or IntelliJ you can do a search / replace on a huge number of PHP files. This might also help if step three is the only option.

The third possibility is not good because it means a lot of work ... good luck!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download