강의 컨설팅 트레이닝 무료진단 무료책자 마케팅편지 마케팅정보공유 다이어리 서비스제휴 고객센터

php 세션css
작성자 : 13 김영철
등록날짜 : 2009.01.13 12:51
1,813
In this tutorial I will try to teach you an experimental method for hiding CSS files I came up with a while ago.

We're going to use .htaccess and PHP for this.

This is what we are going to do:
In the index file, before we include the CSS file, we're setting a key (using sessions) and in the CSS file, we check if the key is set and if it's not, we make it stop executing the code so it wont output any CSS. And if the key is set, we output the CSS code and change the key to something else.

So basicly, the CSS file won't work without the index file, because that's where the key is set.

Still don't get it?
Don't worry, you'll understand when we're done coding it.

Let's start by creating a file called index.php with this code inside:

<?php
session_start();
$_SESSION['csskey'] = "hello";
?>

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
Hello World
</body>
</html>


It's very important that you don't use session_start(); before any output is sendt back to the visitor. So we're putting it at the top.
$_SESSION['csskey'] = "hello"; -That's our key. We store the key in a session called csskey.

Now it's time for the CSS file, but since we're going to check if the session is set, we need to use PHP, so we'll have to call the file style.php NOT style.css.


<?php
session_start();
header("Content-type: text/css");

if ($_SESSION["csskey"] != "hello") {
die("Protected");
}

$_SESSION["csskey"] = "somethingelse";
?>

body {
background-color: #000;
color: #fff;
}


We use session_start(); here too, and then we set the content-type to text/css so the browser will interpet it as a CSS file (not really necessary)
Then we check if the csskey is NOT set to "Hello" and if it isn't we call die() wich stops the script and outputs "Protected".
If the key is set and is correct, we set the csskey to "somethingelse" so that it can't be used again without beeing called from index.php

And for the final step, create a file called .htaccess with this inside:

RewriteEngine on
RewriteRule style.css style.php


This will make style.php "look like" style.css.
So when someone tries to open style.css they will get the contents of style.php.

Try uploading these three files and run it.
If it works, index.php will output "Hello World" with white text and black background.
Also, try looking at style.css from your browser, all it should say is "Protected".

This method is far from bulletproof but it's better then nothing if you want to protect your CSS from rippers. 

[출처] 웹디황용

"쇼핑몰·홈페이지·오픈마켓
블로그·페이스북·이메일 등의 각종 마케팅 글쓰기,
각종 광고, 영업, 판매, 제안서, 전단지
반응율 3배×10배 이상 높이는 마법의 8단계 공식"
자세히보기

Comments

번호 제목 글쓴이 날짜 조회
2685 HTML 태그 제거 스크립트 13 김영철 01.13 1804
2684 문자열함수 13 김영철 01.13 1804
2683 form(2) 99 단국강토 02.09 1805
2682 제로보드에 RSS를 지원하기 - zero2rss 13 김영철 01.13 1805
2681 라이브러리 없이 그래프 그리기 13 김영철 01.14 1805
2680 새로고침때 현페이지 유지 13 김영철 01.14 1805
2679 회색바탕에 움푹파인듯한 느낌의 스타일시트 M 최고의하루 12.26 1806
2678 자바스크립트 - String 객체, Screen 객체 99 단국강토 02.16 1806
2677 Session 값 얻어 내기 13 김영철 01.13 1806
2676 SQL : T-SQL문 : T-SQL(Transact-SQL)문법 13 김영철 01.23 1806
2675 달력 포멧 스크립트 M 최고의하루 12.19 1809
2674 소스 보기방지 우측 마우스 드래그 금지 99 단국강토 01.05 1809
2673 mime_type 알기 13 김영철 01.14 1809
2672 출력버퍼링 예제 13 김영철 01.13 1809
2671 정규표현식의 규칙 13 김영철 01.14 1809
2670 mime_type 알기 13 김영철 01.14 1809
2669 몇가지 sql 명령어 13 김영철 01.23 1809
2668 [펌] 스크롤바 따라 다니는 메뉴 만들기 M 최고의하루 12.26 1810
2667 메일 보내기 소스 - fsocketopen 13 김영철 01.13 1810
2666 MSSQL SERVER에서 접속 port 변경하기 99 단국강토 01.06 1810
2665 php에서 유니코드 인코딩하기 13 김영철 01.13 1812
2664 파라미터 정리 13 김영철 01.14 1813
2663 한글 및 이미지 정렬 M 최고의하루 12.19 1814
2662 [PHP] PHP5에서의 객체지향프로그래밍 13 김영철 01.13 1814
열람중 php 세션css 13 김영철 01.13 1814
2660 [JS] 자바스크립트 typeof[(expression]] 99 단국강토 02.16 1815
2659 png 13 김영철 01.13 1815
2658 트랙백 13 김영철 01.13 1816
2657 100~200까지 3과 5의 배수의합을 13 김영철 01.13 1817
2656 PHP FTP함수 13 김영철 01.14 1817
마케팅
특별 마케팅자료
다운로드 마케팅자료
창업,경영
기획,카피,상품전략
동기부여,성취