All line break removed in the server files - php

I am working on Wordpress.
After upload my project file in the live server and then for any certain changes, I found everything inside "styles.css" files comes into only one line.
Even what ever inside the "header.php" or "footer.php" also comes into only one line.
Then its become hardest to search any particular keyword.
Can anybody please suggest me, how do I prevent this kinda editing in the server?
I am using "NetBean 7" as the editor.

Your server has converted your file types to match the server's file system it sounds like. Your line breaks might be gone. Try opening them in Notepad++ or vim to be sure.
If you look at it in Windows under Wordpad it should work too.

Related

PHP Files Throw Parse Errors (ex: T_STRING) After Migrating

This is a weird one, and something I've never run into before.
I'm deploying to a vvv (Varying Vagrant Vagrants) box from PHPStorm, and the project is a wordpress site.
Frequently, when files are moved over, after reloading the site, I get a PHP parse error, always at the last line of the file. The file isn't necessarily the one I opened and edited, and adding a ?> to the end fixes it. I can then immediately remove the ?> at the end of the file, and all remains well.
This occurs intermittently, making it very difficult to isolate and fix.
An example parse error would be something like:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting end of file in /srv/www/cpr/public_html/wp-content/plugins/jetpack/3rd-party/class.jetpack-amp-support.php on line 359
The specific parse error changes; it's not always the same thing, but it is always fixed by simply adding a ?>, refreshing, etc.
I keep thinking this has to be something to do with either line endings or encoding, but both seem to be ok. (PHPStorm using LF and UTF-8.
The only part of this workflow that is new to me, is the vvv box, as I've previously used other vendors' vagrant boxes, but I'm not sure how that would cause this.
Is something being appended to these files that's breaking when PHP goes to parse them? Is git or vagrant or PHPStorm's deployment overriding line ending rules and changing them?
I'm at a total loss.
Any help is greatly appreciated. As I roll out larger plugin changes, I'm unable to use the WP api, or do anything else without manually opening all the affected files and adding PHP closing tags, then removing them.
I was able to finally track down the cause of this by isolating the various components.
I ruled out phpStorm and git by migrating some files manually and getting the same error to occur above the app's root, on the vagrant box. This isolated the issue to the vvv box itself, and not the project, PHPStorm, or the deploy settings.
I then setup git to force linux line endings via a .gitattributes file in the repo root, with settings based on things I read in this thread.
Here's what I'm using now:
# Force provisioning script to use LF, even on Windows
* text eol=lf
# Avoid binary files to be corrupted by CRLF conversion
*.png binary
*.gif binary
*.jpg binary
*.jpeg binary
I then used dos2unix and find to recursively fix all the line endings in the project, like so:
find . -name '*.php' |xargs dos2unix
So far - all is well, and persisting. I'll update if this pops back up and needs further revision.

Editing hard or softlink's target location content with PHP

I know this is a security threat and is bad from a security aspect alltogether, but for a specific reason, i need this to work. I have a program running on Ubuntu 16.04. Let's say for this example, that it's a DNS server or whatever.
What i'm trying to do, is edit the DNS server configuration file, located in /etc/xxx from a web page, which is using PHP fopen, fwrite and fclose. Because you can't access a file directly located in /etc/xxx/somecfg.cfg anyways, since it doesn't have www-data permissions, i've tried linking it to /var/www/html, both soft and hard linking it. When i create a hard link, it changes the original cfg file too if i edit it by hand, but as soon as i edit it via PHP, only the hard-link file changes, but not the original file.
I've been trying to fix this during the weekend but i can't seem to be able to do it.
Does anyone have an idea on how i would go about fixing this? I'm open to other ideas too. The main goal is to edit a package configuration file from within a web page.
TL;DR: I'm trying to edit a config file in /etc/xxx from /var/www/html/someaction.php and doing it directly doesn't work (obviously), but hard links and soft links are acting weird - the links' content changes, but the original cfg file doesn't.
Thanks!
The issue was that i accidentally put unlink at the beginning of the code and the hard link was deleted, so i basically made a new file each time i wrote to it.
It's fixed now.

Delete specific line from php file

My site got hacked and at every first line of php 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 sed functions but i do not know how to use it and after some discussion i know that will not solve my problem so now i am looking a way how to scan and remove viruse from my files. Any help would be okay.
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!

PHP-Files magically serverd with a leading TAB

I got a weired behavior on my apache, php setup on debian system.
I tried to create an image with php and output it directly. It failed permanent and the browser said sth. like corrupt image file. After a lot of try and error arroun 3 hours I figured out that there is a TAB character added right at the beginning ob my image content, that does not belong there.
To proove that its part of the apache-php setup I created a test.php file, that just contains the letter 'a' and coppied this file to test.html. So Both files just contain the letter a.
You can see the resulting tab here:
http://www.activeroom.net/test.php
http://www.activeroom.net/test.html
and even on the base url itself - its a php-file, too.
Hope anybody can point me in the correct direction. Btw. on the console everything is fine: php test.php just returns an a. Maybe it is something about the Apache MimeTypes or headers?!
How stupid - there was a php-file prepended through the php.ini. That file had a tab at the end. Sometimes things are really messed up.

New line before header()

I'm working with a custom made Joomla script that generates an image from a blob in a database. However, when we moved it from an Apache server to an IIS server, the script is breaking.
Upon investigation, it seems that now, there is a line break that is getting appended before the header function is being run (when I comment out the image portion, and do an echo "test";, test gets printed on line 2 of the source code.
I've gone through the script over and over again, and through the many files in the component, and can't seem to find out where this new line is coming from. At all.
I've tried using ob_start() and many similar functions, but nothing seems to work.
I'm completely out of ideas, and don't know where to turn.
Is there a way to trace what files are being called in the page, perhaps? Any thoughts on further steps?
Look out for additional whitespace at the end of PHP files. If a PHP file ends in more than a single return after the last ?>, that stuff gets printed regardless of where the file is/was included. That is a common error source in larger PHP projects and would meet your symptoms.
(To circumvent this, some have started with a coding standard that prohibits the last ?> in their source files, which is perfectly legal PHP.)
Be careful, maybe it's an encoding problem. Open the file with vim under linux to see if there an ^M or something like that.

Categories