Jump to content
Sign in to follow this  
louie

Protecting CSS files

Recommended Posts

Is there a way to protect CSS files? Is there a way to somehow encrypt it? Or are there other means of doing it?

Why would you want to protect your css files? :)

Share this post


Link to post
Share on other sites

First, don't post the file there, second, do a really complex way of posting it through js. For example.x = sy=cz=riptdocument.write("\<"x+y+z+" src=\"\"\>")If you wanted to cloak a script src. Most people use the find option for webpages, so that would hide it.

Share this post


Link to post
Share on other sites
First, don't post the file there, second, do a really complex way of posting it through js. For example.x = sy=cz=riptdocument.write("\<"x+y+z+" src=\"\"\>")If you wanted to cloak a script src. Most people use the find option for webpages, so that would hide it.

Interesting concept... :)But I'd use:w=sx=cy=rz=iptso you can write "src" with "w"+"y"+"x"<wxyz wyx="something.xww" />:)

Share this post


Link to post
Share on other sites

Rofl, great point. But now on to his question.Do the same thing we just showed you, except with <link rel="Stylesheet" .... etc.>

Share this post


Link to post
Share on other sites

And, if you want to, you can even put the javascript code in an external file, and hide that too... :)

Share this post


Link to post
Share on other sites
Why would you want to protect your css files? :)

Why would i want to protect my CSS files? coz a lot of people would just simply steal your code/layouts and claim it as theirs. you wouldnt want another copy of your website elsewhere. some people would simply copy/paste your code and (not even change a thing!) then they have an instant website, courtesy of you. But its not really a big deal. i was just wondering how to do it.

Share this post


Link to post
Share on other sites
Why would i want to protect my CSS files? coz a lot of people would just simply steal your code/layouts and claim it as theirs. you wouldnt want another copy of your website elsewhere. some people would simply copy/paste your code and (not even change a thing!) then they have an instant website, courtesy of you.

I suppose. But it's through other people's code that you learn stuff. I for one have learned a lot by looking at other people's html and css. My own pride keeps me from just stealing another website, but I guess that doesn't apply to everyone... :)

Share this post


Link to post
Share on other sites
:) darn stealers! (not the football team! :))Well, if you want the complete code thing to hide the css, this is how it would go.<script src="http://hostofscript/script.js"></script>Inside that hosted script, would be this:document.write("<link rel=\'Stylesheet\' href=\'\' type="text/css">Where all bolded parts are up to you. I need a second opinion;would this work?

Share this post


Link to post
Share on other sites

Thanks a lot guys for the help/info. i tried doing one of your suggestions. it worked out quite fine but i figured it would be useless. coz i checked the temporary internet files folder. the css is always there. no matter what. the browser needs it i figure.but anyway. thanks a lot for the help.

Share this post


Link to post
Share on other sites

Maybe you could try to execute a stylesheet by PHP, which won't be visible in the source :)But an external CSS file, would always be visible for the browser in the end... Writing in PHP makes it internal, so making it directly visible in the source code.

Share this post


Link to post
Share on other sites

<?php$txt="<link rel=\'Stylesheet\' href=\'\' type="text/css";echo $txt;?>I guess..i don't know php. would that work?

Share this post


Link to post
Share on other sites
<?php$txt="<link rel=\'Stylesheet\' href=\'\' type="text/css";echo $txt;?>I guess..i don't know php. would that work?

I'm pretty sure that would be the equivalent to javascript's document.write('...')But I could of course be wrong...

Share this post


Link to post
Share on other sites

Are you playing Memory? :)Yes, that PHP would be the same as the javascript thing.Something like this:<?php$fr = fopen("your_CSS_file.css",r);while (!feof($fr)) { echo fgetc($fr,1000); }?>It may be invalid PHP, inthere I am a beginner. But like this, you'd write the CSS file directly inside the current file, so it would turn into internal, no css file needed.Use this information whatever you like :)

Edited by Dan The Prof

Share this post


Link to post
Share on other sites
Are you playing Memory? :)

Either that, or I'm playing humble... :)

Share this post


Link to post
Share on other sites
Wierd. Except, it has nothing on the page! :)

Share this post


Link to post
Share on other sites

i think somehow i found what im looking for. http://www.rlrouse.com/html-encryptor.htmlIt uses javascript. And you can encript not just css... They can still view/save the css file but in an encripted format and i dnt really think they can edit it that easily because they have to decrypt it first. But maybe there is still a downside.there is also an offline version for it.Tell me what you guys think. :)

Share this post


Link to post
Share on other sites
(Chocolate570 @ Oct 17 2005, 10:54 PM)<?php$txt="<link rel=\'Stylesheet\' href=\'\' type="text/css";echo $txt;?>I guess..i don't know php. would that work?
I'm pretty sure that would be the equivalent to javascript's document.write('...')
No, that's incorrect... PHP compiles at run time, completely unlike Javascript. This means that you write the code (as above) and when a user hits that page, PHP spits out the proper html, so you aren't encoding anything. Even if you were to try to right click->'save target as' on the link referring to the page, it would only show the compiled page... never the original source code. This is because it's a server-side language (like ASP, ASP.NET, Java, JSP, Coldfusion, etc) which means it compiles right before it's sent to you (on the host server).
<?php$txt="<link rel=\'Stylesheet\' href=\'\' type="text/css";echo $txt;?>would still output:<link rel='Stylesheet' href='' type="text/css"

(on a side note... that line of code would error because the quotes around text/css aren't backslashed as well)Moving on... Javascript always shows the source code and compiles based on the user's browser. It's called a 'client-side' language. Have you ever noticed that Javascript will work differently in different browsers? That's because of what I'm saying... Javascript doesn't hide source code (and never will), while PHP will always hides source code. Two completely different languages.I hope this makes sense to you and I helped shed some light on that.Finally, a good note! http://scriptasylum.com/tutorials/encdec/encode-decode.html is a good way to encode your javascript so it's difficult to for anyone to steal. Doesn't mean it's impossible, just that it will knock out 99% of the people trying. Just make sure your javascript is perfect before you encode it, AND DON'T FORGET TO SAVE YOUR ORIGINAL JAVASCRIPT!Happy coding!

Share this post


Link to post
Share on other sites

So we have come to the conclusion, that CSS style files will be stored at the user's pc, for later reuse, and that the user can refer to it and steal the content.I do not know many about the following, but it might work.How about, expire the cached file? Would it then be deleted after the expire date, or directly downloaded after that date when called again?If the first case is true, try to write the css with php, and sent a content-type header. (header before the content) Set expire date exactly the current time plus 1 (to ensure the file can be used at all).This way the file gets deleted directly after use, instead of leaving it in the cache.Right?

Share this post


Link to post
Share on other sites

Either way, I would still be able to directly call the CSS by viewing the source and typing the absolute path into my browser. Then I'd just need to copy and past the contents.To my knowledge, there is no way you will truely be able to protect your CSS. Scripting language code is different since it is processed - CSS files are just referenced.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×