mubashermubi
mubashermubi

Reputation: 9256

How to edit css files using php safely?

I have been thinking from a long time that how can I edit the css files using php very safely and securely as we know css files are easily accessible and any one get the data using file_get_contents.

My question is can anyone edit the css file using file_get_contents?

Or is it safe to use while editing css file using this code?

$filename = "stylesheets/".$_POST['filename'];
$code = $_POST['code'];
if( file_exists($filename) ){
    file_put_contents( $filename, stripslashes($code) );
    echo 1;
}

I am just curious about it that I am using a very insecure way and anyone can access my css file and make changes even can destroy all my styling. I searching for the best and secure way to edit css files.

Please let me know if it is a possible duplicate or not a good question to ask, so I can close it my self and not by down votes.

Thank you.

Upvotes: 0

Views: 89

Answers (1)

Seer
Seer

Reputation: 5237

This question doesn't really make much sense, but; how would anyone be able to edit the file? They'd need access to your server. If they used a script, it'd have to be on your server. I couldn't just make a random script run it on my PC or something and edit a file, it'd have to have direct access to the filesystem, and even then - the user PHP is running as would need to have write access to the file on top of that.

Is there a specific security concern you have? There doesn't seem to be a problem with what you're doing.

Upvotes: 1

Related Questions