homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderators: not2easy

CSS Forum

Possible way to prevent stylesheet ripping
But I need help with one last bit.

 9:00 am on May 14, 2008 (gmt 0)

OK, so I have the <link> tag in my header pointing to style.php. This is the top part of style.php:

$myURL = "http://foo.com/style.php";
$currentURL = $_SERVER['PHP_SELF'];
if (strlen($_SERVER['QUERY_STRING']) > 0) $currentURL .='?'.$_SERVER['QUERY_STRING'];
$currentURL = "http://foo.com" . strtolower($currentURL);
$myURL = strtolower($myURL);
if($currentURL == $myURL){
die("Please, don't insult us by trying to rip our css!");
header('Content-type: text/css');
} ?>
css code here

Good news: if you directly access the page, you just get "Please, don't insult us by trying to rip our css!"

Bad news: both <link> and @import don't return the css.

Is there another solution that will allow us to use the css without adding it into the source code of the page?



 9:39 am on May 14, 2008 (gmt 0)

Most visitors to your site have no clue what CSS is, and they won't be interested in the CSS. People that want to know how you do things in the CSS also know how to get the CSS by using e.g. the Firebug or Webdeveloper plug-ins for FF. So don't bother hiding it.
But if you want to use your method, the check for $currentURL == $myURL should be $currentURL != $myURL but that will always be ok, as you have no variables ($myUrl will never change and also $currentURL will never change in case there is no query string) in your code so it will always return the CSS.
The only thing you can do is checking the referer, but also that is easy to circumvent.


 10:18 am on May 14, 2008 (gmt 0)

I think you misunderstand me: I'm not trying to stop hotlinking, I've already done that. The piece of code I was using above is to try and stop people from directly visiting the css stylesheet, so they can't just copy/paste and rip the layout & use it themselves. Any ideas?


 11:35 am on May 14, 2008 (gmt 0)

Why would anyone else even WANT to use your stylesheet?

And you can't stop them anyway, there are numerous ways to just download the whole website if they really want it.

[edited by: Wlauzon at 11:36 am (utc) on May 14, 2008]


 12:02 pm on May 14, 2008 (gmt 0)

piece of code I was using above is to try and stop people from directly visiting the css stylesheet, so they can't just copy/paste and rip the layout & use it themselves

This is hilarious. You can't do anthing about it. HTML, CSS, Javascript...you can't protect that stuff. Is your layout so amazing that people want to steal it though?

People don't care about that stuff as much as you think, the important part is how the site functions...which should be with a server side language that's already protected. If someone does copy your site layout you can always tell their host to shut them down, not too hard.


 12:25 pm on May 14, 2008 (gmt 0)

I'm with the 'whys'!

Aside from what is already mentioned that there are numerous ways to "view" a stylesheet, CSS on its own is not particularly useful for "ripping" layouts, you need the HTML structure and the background image/sprite structure.

Most who are even interested in viewing the source to and "copying" code are usually learners trying to figure out techniques or advanced users looking to compliment. Full site rips are usually ripped for their content before code. And then there's the "imitation is the sincerest form of flattery" notion.. Fashion designers and artists have to cope with it all the time, and they still get big money commissions - so as has been said many times before if you don't want it copied don't put it on the Web :)

hmmm. rather than spending time fighting a useless corner, You could turn it into a money making exercise.. Sell your template, minus the custom graphics, internal custom classes etc, that way if someone really wants the layout, I'm pretty sure they will pay a few bucks for the zip file to save them having to weed out your site specific code, just let them know the sizes of the images they will need to replace your custom ones for minimal effort ;)


 2:35 pm on May 14, 2008 (gmt 0)

Along those lines, the company I work for once asked me to prevent people from downloading the banner ads we have on the site. Why anyone would want to do that in the first place is beyond me, but anyways, I showed them about six different ways to get the source code, and if that didn't work, I showed them that innocent, little "Print Screen" button. They told me to stop wasting my time implementing their idea ;)

I don't want to antagonize dawmail333. No one likes their stuff stolen, and I can understand where he's coming from, but if the page is open in the browser, there's just no way to protect what's on it. I agree with SuzyUK, zip up the layout and sell it. You can make a bundle with templates.



 4:42 pm on May 14, 2008 (gmt 0)

If you let the browser have it those who want to know what's inside to copy/imitate it will have it too.

There's nothing you can do to stop them, and the more you try, the more interesting it is to get it anyway.

Although I'd advise against it, the best you can achieve (but it's like shooting in your own foot) is to obfuscate the names of the classes and IDs.

Using e.g. classes and IDs that are like
makes understanding it all pretty impossible (but that goes for yourself just as well).

But your potential copycat will have a computer too and could easily revert all the changes.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved