Virtusertable

참고 ~ http://www.oops.org/lecture.php?n=4&sb=sendmail


이 part는 virtual hosting시에 여려명의 user가 서로 같은 계정을 요구할때의 곤란함을 해결하기 위한 방법을 제시한다. 이 방법은 sendmail의 virtual user table을 이용하며 sendamil의 compile 방법 및 기본 설정에 대해서는 KLDP에 한글 자료가 있으니 참고하기를 바라고, 이 강좌에서 설정할 virtual user table 기능을 추가하기 위해서는 sendmail의 공식 홈페이지에서 virtual hosting 관련 page를 참고하기 바란다. 또는 FTP 의 sendmail을 이용하는 것도 가능하다. 또한 요즘의 왠만한 배포본에 들어 있는 sendmail 의 경우에는 기본적으로 지원을 하는 추세이다.



Hanterm – cat /etc/mail/virtusertable

[root@oops mail]# cat virtusertable

# 이 file은 virtual user를 설정하는 file이다.
# 실제로 없는 계정을 mapping 할수 있으며, 같은 이름 역시
# domain 별로 다르게 mapping 할수 있다.
#                                                                      
# 작성후
# makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable
# 명령을 실행 해 줘야 한다.
#
#                  작성  김정균. <admin at oops.org>      

admins@oops.org bbuwoo@chollian.net
sales@oops.org oops
help@oops.org oops
                                                  
admins@abc.co.kr abc
sales@abc.co.kr abc
help@abc.co.kr abc@abc-kr.co.kr      
@abc.co.kr error: nouser Unknown User

@asdf.com asdf
@bbc.co.kr %1@other.oops.org

[root@oops mail]#





이 file은 sendmail의 virtual user를 이용하기 위한 설정 file이다. virtual user table을 이용하기 위해서 즉, 이 file을 이용하기 위해서는 /etc/mail/sendmail.cf에서


Kvirtuser hash /etc/mail/virtusertable
과 virtual user handle 이 정의 되어 있어야 하며 FTP 에서 받은 package에는 미리 이 설정들을 정의를 해 놓았으니 걱정할 필요는 없다.

그럼 위의 file에서 설정한 것들에 대해 간단하게 설명을 하겠다. 이 설정으로 보아 이 설정 file이 존재하는 host에는 oops.org 이라는 domain과 abc.co.kr 이라는 2개의 domain을 가지고 있는 것으로 예상을 할수가 있다. 그리고 대충 눈치를 보아서 oops라는 계정과 abc라는 계정을 가지고 있다는 것도 눈치가 빠른 사람이라면 금방 알수 있을 것이다.

그럼 간단하게 세 줄을 가지고 이 file에 대해서는 설명을 할수가 있다.


admins@oops.org bbuwoo@chollian.net
admins@abc.co.kr abc
@asdf.com asdf


보통 sendmail에서 위의 하나의 host에 여러개의 account를 가지고 있다고 해도 e-mail address의 ID가 같다면 모두 동일한 계정으로 가게된다. 하지만 sendmail 의 Virtual User Table을 사용하여 위와 같이 설정을 함에 따라 admin이라는 계정이 없음에도 불구하고 또한 같은 account 임에도 불구하고 mail address의 domain에 따라서 admins@oops.org으로 가는 mail은 bbuwoo@chollian.net 으로 mapping 하며, admins@abc.co.kr 으로 가는 mail을 abc 라는 계정으로 갈수 있게 하는 것이다. 앞부분은 가상의 e-mail account가 되는 것이며 뒷부분은 가상의 e-amil address로 오는 mail을 실제로 받는 계정이 된다. 또한 마지막 예는 asdf.com으로 보내는 메일은 어떤 계정으로 보내더라도 모두 asdf 라는 계정으로 메일을 가게 하는 것을 뜻한다.

localhost의 account로 mapping을 할수도 있으며, 다른 host의 account로도 mapping이 가능하다. 이 virtual user table을 잘만 이용한다면 aliases는 별 사용할 필요가 없어 지기도 한다.

그럼 다음의 예를 보도록 한다.


  @abc.co.kr error: nouser Unknown User
  @bbc.co.kr %1@other.oops.org


위에서 이 설정들의 용도를 살펴 보자면 일단 첫번째줄 부터 설명을 하겠다. 첫번째 줄의 경우 admins@abc.co.kr, sales@abc.co.kr, help@abc.co.kr 외에 abc.co.kr 이라는 도메인으로 오는 메일들은 virtusertable에서는 해당 설정이 없기 때문에 다음 단계인 aliases file로 넘어가게 되며 aliases에서도 해당 설정이 없으면 실제 계정을 찾게 된다. 그럼 문제는 대형 메일 서버일경우 이렇게 실제 계정을 찾는 단계까지 갔음에도 불구하고 없는 계정이라면 상당한 서버 부하를 가져 올수도 있는 문제가 발생한다. 그래서 이 설정을 함으로서 admin, sales, help 외의 계정으로 abc.co.kr이라는 도에민으로 오는 메일들은 virtusertable 차원에서 return을 시켜 버리는 역할을 하게 되는 것이다. 잘 사용하면 그만큼 부하를 낯출수도 있는 것이다.

그럼 다음줄을 보면 이상한 것을 볼수 있다. 즉 “%1” 이라는 표현법을 볼수 있다. 이 %1은 실제 메일 header에 들어 있는 메일 주소의 account부분 즉 admins@abc.co.kr로 온 메일이라면 이중 admin 을 %1에 match를 하게 된다.

이 file의 설정을 끝냈다고 해서 설정이 그대로 적용되지는 않는다. sendmail에서는 대체로 text 설정 file들을 DB화 하여 db file들을 이용하여 설정을 적용시킨다. 이 virtusertable file을 db화 하여 놓은 file이 /etc/mail/virtusertable.db 이다. virtusertable을 db file로 적용시키기 위하여 virtusertable을 저장한 후에 shell에서


makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable
명령으로서 virtusertable.db file을 갱신 시켜 줘야 한다. 만약 NDBM으로 sendmail을 compile했다면 모든 설정 file들의 hash를 dbm 으로 바꾸어 줘야 한다. hash는 버클리 DB(NEWDBM)을 의미한다.
이곳의 패키지를 설치를 했다면 좀더 쉽게 할수가 있다. /etc/mail밑에 보면 makemap.sh 라는 file이 존재를 한다. 그럼 /etc/mail 로 이동을 하여 SHELL> ./makemap.sh virt 를 실행하면 위의 방법과 동일한 결과를 가져 온다.

이 정도면 virtual user table에 대한 설명은 끝났다. 좀더 정밀한 setting은 이 page의 상단에 link되어 있는 sendmail page의 virtual hosting 문서를 살펴 보기 바란다.

웹서버 및 웹메일 설정 방법

# 가상 유저 (virtual user) 설정방법

/etc/mail/virtual***
파일에 설정하고자 하는 user를 설정하고 다음과 같이 실행
rm -rf *.db
make
/etc/rc.d/init.d/sendmail restart


# 다중 도메인 (virtual domain; 가상 도메인) 설정 방법

/etc/mail/local-domain-names 파일에 쓰고자하는 도메인명을 추가하고 다음과 같이 실행

rm -rf *.db
make
/etc/rc.d/init.d/sendmail restart


# POP3 서버 및 SMTP 서버 설정 방법
자세한 것은 첨부파일 참조…

음력-양력 변환기

$Lunar_Month = array(
/* 1881 */ // 1881년 1월 30일은 음력 1월 1일
    “1”,”2″,”1″,”2″,”1″,”2″,”2″,”3″,”2″,”2″,”1″,”2″,”1″,   “1”,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”0″,
    “1”,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,”2″,”0″,   “2”,”1″,”1″,”2″,”1″,”3″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,  
    “2”,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”0″,   “2”,”1″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”0″,
    “2”,”2″,”1″,”2″,”3″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,   “2”,”1″,”2″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”0″,  
    “2”,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”0″,   “1”,”2″,”3″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,  
/*1891*/
    “1”,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”0″,   “1”,”1″,”2″,”1″,”1″,”2″,”3″,”2″,”2″,”1″,”2″,”2″,”2″,
    “1”,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,”0″,   “1”,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”0″,  
    “2”,”1″,”2″,”1″,”2″,”3″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,   “2”,”2″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”0″,
    “1”,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”0″,   “2”,”1″,”2″,”3″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,  
    “2”,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”0″,   “1”,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”3″,”2″,”2″,”1″,”2″,  
/*1901*/
    “1”,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,”0″,   “2”,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,”0″,
    “1”,”2″,”1″,”2″,”1″,”3″,”2″,”1″,”1″,”2″,”2″,”1″,”2″,   “2”,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”2″,”1″,”0″,  
    “2”,”2″,”1″,”2″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”0″,   “1”,”2″,”2″,”1″,”4″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,
    “1”,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”0″,   “2”,”1″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”0″,  
    “1”,”2″,”3″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,”2″,   “1”,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,”0″,  
/*1911*/
    “2”,”1″,”2″,”1″,”1″,”2″,”3″,”1″,”2″,”2″,”1″,”2″,”2″,   “2”,”1″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”2″,”1″,”2″,”0″,
    “2”,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”0″,   “2”,”2″,”1″,”2″,”2″,”3″,”1″,”2″,”1″,”2″,”1″,”1″,”2″,  
    “2”,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”0″,   “1”,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”0″,
    “2”,”1″,”3″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,   “2”,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,”2″,”0″,  
    “1”,”2″,”1″,”1″,”2″,”1″,”2″,”3″,”2″,”2″,”1″,”2″,”2″,   “1”,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”2″,”1″,”2″,”2″,”0″,  
/*1921*/
    “2”,”1″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”0″,   “2”,”1″,”2″,”2″,”1″,”3″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,
    “1”,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”1″,”2″,”0″,   “2”,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”1″,”0″,  
    “2”,”1″,”2″,”2″,”3″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,   “1”,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”0″,
    “2”,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”0″,   “1”,”2″,”3″,”1″,”2″,”1″,”1″,”2″,”2″,”1″,”2″,”2″,”2″,  
    “1”,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”2″,”0″,   “1”,”2″,”2″,”1″,”1″,”2″,”3″,”1″,”2″,”1″,”2″,”2″,”1″,
/*1931*/
    “2”,”2″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”0″,   “2”,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”0″,
    “1”,”2″,”2″,”1″,”2″,”4″,”1″,”2″,”1″,”2″,”1″,”1″,”2″,   “1”,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”0″,  
    “1”,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”0″,   “2”,”1″,”1″,”4″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,
    “2”,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,”0″,   “2”,”2″,”1″,”1″,”2″,”1″,”1″,”4″,”1″,”2″,”2″,”1″,”2″,  
    “2”,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”0″,   “2”,”2″,”1″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”0″,
/*1941*/
    “2”,”2″,”1″,”2″,”2″,”1″,”4″,”1″,”1″,”2″,”1″,”2″,”1″,   “2”,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”1″,”2″,”0″,
    “1”,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”2″,”0″,   “1”,”1″,”2″,”1″,”4″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,  
    “1”,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,”2″,”0″,   “2”,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”0″,
    “2”,”2″,”3″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,   “2”,”1″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”0″,  
    “2”,”2″,”1″,”2″,”1″,”2″,”1″,”3″,”2″,”1″,”2″,”1″,”2″,   “2”,”1″,”2″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”0″,  
/*1951*/
    “2”,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”0″,   “1”,”2″,”1″,”2″,”1″,”4″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,
    “1”,”2″,”1″,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”0″,   “1”,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”0″,  
    “2”,”1″,”1″,”4″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,   “1”,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”0″,
    “2”,”1″,”2″,”1″,”2″,”1″,”1″,”2″,”3″,”2″,”1″,”2″,”2″,   “1”,”2″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”0″,  
    “1”,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”0″,   “2”,”1″,”2″,”1″,”2″,”2″,”3″,”2″,”1″,”2″,”1″,”2″,”1″,  
/*1961*/
    “2”,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”0″,   “1”,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”0″,
    “2”,”1″,”2″,”1″,”3″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,   “2”,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,”0″,  
    “1”,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”2″,”1″,”0″,   “2”,”2″,”2″,”3″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”2″,”1″,
    “2”,”2″,”1″,”2″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”0″,   “1”,”2″,”2″,”1″,”2″,”1″,”2″,”3″,”2″,”1″,”2″,”1″,”2″,  
    “1”,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”0″,   “2”,”1″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”0″,  
/*1971*/
    “1”,”2″,”1″,”1″,”2″,”3″,”2″,”1″,”2″,”2″,”2″,”1″,”2″,   “1”,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,”0″,
    “2”,”1″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”2″,”2″,”1″,”0″,   “2”,”2″,”1″,”2″,”3″,”1″,”2″,”1″,”1″,”2″,”2″,”1″,”2″,  
    “2”,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”0″,   “2”,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”3″,”2″,”1″,”1″,”2″,
    “2”,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”1″,”0″,   “2”,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”0″,  
    “2”,”1″,”1″,”2″,”1″,”2″,”4″,”1″,”2″,”2″,”1″,”2″,”1″,   “2”,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”0″,  
/*1981*/
    “1”,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”2″,”1″,”2″,”2″,”0″,   “2”,”1″,”2″,”1″,”3″,”2″,”1″,”1″,”2″,”2″,”1″,”2″,”2″,
    “2”,”1″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”0″,   “2”,”1″,”2″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”3″,”2″,”2″,  
    “1”,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”0″,   “1”,”2″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”1″,”0″,
    “2”,”1″,”2″,”2″,”1″,”2″,”3″,”2″,”2″,”1″,”2″,”1″,”2″,   “1”,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”0″,  
    “2”,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”0″,   “1”,”2″,”1″,”1″,”2″,”3″,”1″,”2″,”1″,”2″,”2″,”2″,”2″,  
/*1991*/
    “1”,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”2″,”0″,   “1”,”2″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”0″,
    “1”,”2″,”2″,”3″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,   “2”,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”0″,  
    “1”,”2″,”2″,”1″,”2″,”2″,”1″,”2″,”3″,”2″,”1″,”1″,”2″,   “1”,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”0″,
    “1”,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”0″,   “2”,”1″,”1″,”2″,”1″,”3″,”2″,”2″,”1″,”2″,”2″,”2″,”1″,  
    “2”,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,”0″,   “2”,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”1″,”0″,  
/*2001*/
    “2”,”2″,”2″,”1″,”3″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,   “2”,”2″,”1″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”0″,
    “2”,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”0″,   “1”,”2″,”3″,”2″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”1″,”2″,  
    “1”,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”2″,”0″,   “1”,”1″,”2″,”1″,”2″,”1″,”2″,”3″,”2″,”2″,”1″,”2″,”2″,
    “1”,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,”2″,”0″,   “2”,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”0″,  
    “2”,”2″,”1″,”1″,”2″,”3″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,   “2”,”1″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”0″,  
/*2011*/
    “2”,”1″,”2″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”0″,   “2”,”1″,”2″,”4″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,
    “2”,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”0″,   “1”,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”3″,”2″,”1″,”2″,  
    “1”,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,”2″,”2″,”0″,   “1”,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”0″,
    “2”,”1″,”1″,”2″,”1″,”3″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,   “1”,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”0″,  
    “2”,”1″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”0″,   “2”,”1″,”2″,”2″,”3″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,  
/*2021*/
    “1”,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”0″,   “2”,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”0″,
    “1”,”2″,”3″,”2″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,   “1”,”2″,”1″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”0″,  
    “2”,”1″,”2″,”1″,”1″,”2″,”3″,”2″,”1″,”2″,”2″,”2″,”1″,   “2”,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,”0″,
    “1”,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”2″,”2″,”0″,   “1”,”2″,”2″,”1″,”2″,”3″,”1″,”2″,”1″,”1″,”2″,”2″,”1″,  
    “2”,”2″,”1″,”2″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”2″,”0″,   “1”,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”0″,  
/*2031*/
    “2”,”1″,”2″,”3″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,   “2”,”1″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”2″,”0″,
    “1”,”2″,”1″,”1″,”2″,”1″,”2″,”3″,”2″,”2″,”2″,”1″,”2″,   “1”,”2″,”1″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,”0″,  
    “2”,”1″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”2″,”1″,”2″,”0″,   “2”,”2″,”1″,”2″,”1″,”1″,”4″,”1″,”1″,”2″,”1″,”2″,”2″,
    “2”,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”1″,”2″,”0″,   “2”,”2″,”1″,”2″,”1″,”2″,”1″,”2″,”1″,”1″,”2″,”1″,”0″,  
    “2”,”2″,”1″,”2″,”2″,”3″,”2″,”1″,”2″,”1″,”2″,”1″,”1″,   “2”,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”2″,”1″,”2″,”1″,”0″,  
/*2041*/
    “2”,”1″,”1″,”2″,”1″,”2″,”2″,”1″,”2″,”2″,”1″,”2″,”0″,   “1”,”2″,”3″,”1″,”2″,”1″,”2″,”1″,”2″,”2″,”2″,”1″,”2″,
    “1”,”2″,”1″,”1″,”2″,”1″,”1″,”2″,”2″,”1″,”2″,”2″,”0″
);

function is_yun_year($year)
{
        if ($year % 4 != 0) return 0;   /* not yun year */
        if ($year % 100 != 0) return 1; /* yun year */
        if ($year % 400 != 0) return 0;  /* not yun year */
        return 1;                                               /* yun year */
}


function how_many_days($year, $month)
{
    switch($month)
    {
    case 1: case 3: case 5: case 7: case 8: case 10: case 12:
        return 31;
    case 4: case 6: case 9: case 11:
        return 30;
    case 2:
        if (is_yun_year($year)) return 29;
        else return 28;
    }
}

function end_day_of_lunar_month($year, $month)
{
    global $Lunar_Month;

    for ($i = 0; $i < $month; $i++) {
        $flag = $Lunar_Month[$year-1880][$i];
        if ($flag == ‘3’ || $flag == ‘4’) break;
    }
    if ($i != month)
        $flag = $Lunar_Month[($year-1880)*13+$month];
    else $flag = $Lunar_Month[($year-1880)*13+$month-1];

    if ($flag == ‘1’) return 29;
    else return 30;
}

function solar_to_lunar($year, $month, $day)
{
    global $Lunar_Month , $lunar_date;
    $total_day = 0;

    // 해의 범위를 측정한다.
    if ($year < 1881 || $year > 2043) return -1;

    for ($i = 0; $i < 163; $i++) {
        $Sum_of_Lunar_Day[$i]=0;  // 1년의 음력 날자의 합을 저장하는 배열

        $list_of_year[$i]=1881+$i;

        for ($j = 1; $j <= 13; $j++) {
            $this_month = $i*13+$j-1;
            switch($Lunar_Month[$this_month]) {
                case ‘0’:
                    break;
                case ‘1’: case ‘3’:
                    $Sum_of_Lunar_Day[$i] = $Sum_of_Lunar_Day[$i] + 29;
                    $imsi=29;
                    break;
                case ‘2’: case ‘4’:
                    $Sum_of_Lunar_Day[$i] = $Sum_of_Lunar_Day[$i] + 30;
                    $imsi=30;
                    break;
            }
        }
    }

    /* 오늘까지의 양력 날자의 합구하기. */
    /* 1881-1-30이 음력 1월 1일이나깐 1880년까지 날에 29일을 더한다. */
    $sum_of_1881 = (int)(1880*365 + 1880/4 – 1880/100 + 1880/400 + 29);

    /* 입력받은 날까지의 날짜의 합구하기 */
    //— 작년 까지의 날짜의 합 —//
    $last_year=$year-1;
    $sum_of_today = (int)($last_year*365 + $last_year/4 – $last_year/100 + $last_year/400);

    //— 자난 달 까지의 날짜의 합 —//
    for($i = 1; $i < $month ; $i++){
        $sum_of_today = $sum_of_today + how_many_days($year,$i);
    }

    //— 오늘까지의 날짜의 합 —//
    $sum_of_today = $sum_of_today + $day;

    // 오늘까지의 날짜 합에서 1881년 1월 29일의 날짜의 합을 뺀다.//
    // $total_day는 날짜의 차이..
    if($year == 1881) $total_day  = $sum_of_today – $sum_of_1881;
    else $total_day  = $sum_of_today – $sum_of_1881 -1;

    //——————————————————————–//
    // 이제 부터 음력을 계산 한다..
    $total_imsi = $Sum_of_Lunar_Day[0];
    for($i = 0; $i < 163; $i++) {
        if ($total_day <= $total_imsi) break;
        else $total_imsi = $total_imsi + $Sum_of_Lunar_Day[$i + 1];
    }

    $lun_year = $i + 1881; // 음력 년도 구함..

    $ext_total_day = $total_day – $total_imsi + $Sum_of_Lunar_Day[$i];;

    if ($Lunar_Month[$i*13+12] == ‘0’) $count = 12;
    else $count = 13;

    $m2 = 0;
    for ($j = 0; $j < $count; $j++) {
        $this = $i*13+$j;
        if ($Lunar_Month[$this] == 1) {
            $m2++;
            $m1 = $Lunar_Month[$this] + 28;
            $is_yun_month = 0;
        }
        else if ($Lunar_Month[$this] == 2) {
            $m2++;
            $m1 = $Lunar_Month[$this] + 28;
            $is_yun_month = 0;
        }
        else if ($Lunar_Month[$this] == 3) {
            $m1 = $Lunar_Month[$this] + 26;
            $is_yun_month = 1;
        }
        else {
            $m1 = $Lunar_Month[$this] + 26;
            $is_yun_month = 1;
        }

        // 다음달이 윤달인지 아닌지를 리턴한다..
        // 넘기는 이유는 생일자의 쿼리 전송을 위해서..
        // 음력 윤달의 생일자 또는 평달에 태어난 생일자가
        // 윤달이 다음달에도 나오지 않게.
        // 그러니깐 생일이 두번 생기지 않도록

        $next = $i*13+$j+1;
        if ($Lunar_Month[$next] == 1) $next_is_yun_month = 0;
        else if ($Lunar_Month[$next] == 2) $next_is_yun_month = 0;
        else if ($Lunar_Month[$next] == 3) $next_is_yun_month = 1;
        else $next_is_yun_month = 1;


        if ($ext_total_day <= $m1) break;
        $ext_total_day = $ext_total_day – $m1;
    }

    $lunar_year = $lun_year;
    $lunar_month = $m2;
    $lunar_day = (int)($ext_total_day);
    $is_lunar = $is_yun_month;
    $next_is_lunar =$next_is_yun_month;

    if($lunar_month <10) $lunar_month=”0″.$lunar_month;
    if($lunar_day <10) $lunar_day=”0″.$lunar_day;

    $lunar_date = “$lunar_year”.”년”.” “.”$lunar_month”.”월”.” “.”$lunar_day”.”일”;

return $lunar_date;
}
$Y = date(“Y”);
$M = date(“m”);
$D = date(“d”);
solar_to_lunar($Y, $M, $D);
echo $lunar_date;

PHP에서 메일 함수가 동작하지 않을때

 

php.ini 파일에 보면 sendmail 설정 부분이 있습니다. 그곳에 -i 옵션이 설정되어 있는지 확인해보세요.


[mail function]
SMTP                    =       localhost                       ;for win32 only
;sendmail_from  =       me@localhost.com        ;for win32 only
sendmail_path   =       /usr/sbin/sendmail -t -i ;for unix only, may supply arguments as well (default is ‘sendmail -t -i’) (linux 시스템의 일반적인 sendmail 위치.. 확인해보고 바르게 지정해보세요.)

어떤 파라메터가 넘어왔는지 알아내는 함수

 

어떤 변수들이 post 또는 get method로 넘어왔는지 알아낼 수 있는 함수

//HTTP_POST_VARS 란 인수에서 POST 값들을 이름:값 형식으로 하나씩 추출해 냅니다.

while(list($Post_Name, $Post_Val)=each($HTTP_POST_VARS))
{
  echo(“$Post_Name: $Post_Val<br>
“);
}

이 방법을 사용하면 http://m.kurapa.com/?바보=천치 라는 식으로 파라메터를 보낼때

바보라는 파라메터를 사용했는지 알아 낼 수 있다.

참고로 GET Method일때는 다음의 방법을 사용하기 바란다.

  while(list($Post_Name, $Post_Val)=each($HTTP_GET_VARS))
  {
    $rss = $Post_Name;
    break;
  }

웹페이지 긁어서 타이틀 뿌려주는 소스

 $file = @fopen( $url, “r”);
   if (!$file)
   {
     echo “usage $PHP_SELF?url=<the url you want to test>”;
     return 0;
   }

   while (!feof($file))
   {
     $text .= fgets($file, 40960);
     // do something
   }
   fclose($file);

   if (eregi( “<title>(.*)</tltle>”, $text, $output))
   {
     // title found
     echo “the document title is [” . $output[1] . “]”;
   }
   else
   {
     // title not found
     echo “the document title not found”;
   }

PHP로 객체지향 프로그래밍 하는 방법

#######################################################################
## Object Oriented Programming in PHP: The way to large PHP projects ##
#######################################################################

This arcticle introduces Object Oriented Programming (OOP) in PHP. I will show you how to code less and better by using some OOP concepts and PHP tricks. Good luck!

Concepts of object oriented programming: There’re differences between authors, I can mention that a OOP language must have:


Abstract data types and information hidding
Inheritance
Polymorphism
The encapsulation is done in php using classes:

<?php

class Something {
   // In OOP classes are usually named starting with a cap letter.
   var $x;

   function setX($v) {
       // Methods start in lowercase then use lowercase to seprate
       // words in the method name example getValueOfArea()
       $this->x=$v;
   }

   function getX() {
       return $this->x;
   }
}

?>

Of course you can use your own nomenclature, but having a standarized one is useful.

Data members are defined in php using a “var” declaration inside the class, data members have no type until they are assigned a value. A data member might be an integer, an array, an associative array or even an object. Methods are defined as functions inside the class, to access data members inside the methods you have to use $this->name, otherwise the variable is local to the method.

You create an object using the new operator:

$obj=new Something;

Then you can use member functions by:

$obj->setX(5);
$see=$obj->getX();

The setX member function assigns 5 to the x datamember in the object obj (not in the class), then getX returns its value: 5 in this case.

You can access the datamembers from the object reference using for example: $obj->x=6; however, this is not a very good OOP practice. I enforce you to set datamembers by defining methods to set them and access the datamembers by using retrieving methods. You’ll be a good OOP programmer if you consider data members inaccesible and only use methods from the object handler. Unfortunately PHP doesn’t have a way to declare a data member private so bad code is allowed.

Inheritance is easy in php using the extend keyword.

<?php

class Another extends Something {
   var $y;
   function setY($v) {
       // Methods start in lowercase then use lowercase to seperate
       // words in the method name example getValueOfArea()
       $this->y=$v;
   }

   function getY() {
       return $this->y;
   }
}

?>

Objects of the class “Another” now has all the data members and methods of the parent class (Something) plus its own data members and methods. You can use

$obj2=new Something;
$obj2->setX(6);
$obj2->setY(7);

Multiple inheritance is not supported so you can’t make a class extend two or more different classes.

You can override a method in the derived class by redefining it, if we redefine getX in “Another” we can’t no longer access method getX in “Something”. If you declare a data member in a derived class with the same name as a data member in a Base class the derived data member “hides” the base class data member when you access it.

You might define constructors in your classes, constructors are methods with the same name as the class and are called when you create an object of the class for example:

<?php

class Something {          
   var $x;

   function Something($y) {
       $this->x=$y;
   }

   function setX($v) {    
       $this->x=$v;          
   }

   function getX() {
       return $this->x;
   }
}

?>

So you can create an object by:

$obj=new Something(6);

And the constructor automatically asigns 6 to the data member x. Constructors and methods are normal php functions so you can use default arguments.

function Something($x=”3″,$y=”5″)

Then:

$obj=new Something(); // x=3 and y=5
$obj=new Something(8); // x=8 and y=5
$obj=new Something(8,9); // x=8 and y=9

Default arguments are used in the C++ way so you can’t pass a value to Y and let X take the default value, arguments are asigned form left to right and when no more arguments are found if the function expected more they take the default values.

When an object of a derived class is created only its constructor is called, the constructor of the Parent class is not called, this is a gotcha of PHP because constructor chaining is a classic feature of OOP, if you want to call the base class constructor you have to do it explicitely from the derived class constructor.It works because all methods of the parent class are available at the derived class due to inheritance.

<?php

function Another() {
   $this->y=5;
   $this->Something();   //explicit call to base class constructor.
}

?>

A nice mechanism in OOP is to use Abstract Classes, abstract classes are classes that are not instanciable and has the only purpose to define an interface for its derived classes. Designers often use Abstract classes to force programmers to derive classes from certain base classes so they can be certain that the new classes have some desired functionality. There’s no standard way to do that in PHP but:

If you do need this feature define the base class and put a “die” call in its constructor so you can be sure that the base class is not instanciable, now define the methods (interface) putting “die” statements in each one, so if in a derived class a programmer doesn’t override the method then an error raises. Furthermore you might need to be sure since php has no types that some object is from a class derived from you base class, then add a method in the base class to identify the class (return “some id”), and verify this when you receive an object as an argument. Of course this doesn’t work if the evil programmer oveerides the method in the derived class but genrally the problem is dealing with lazy programmers no evil ones! Of course is better to keep the base class unreachable from the programmers, just print the interface and make them work!

There’re no destructors in PHP.

Overloading (which is different from overriding) is not supported in PHP. In OOP you “overload” a method when you define two/more methods with the same name but different number or type of parameters (depending upon the language). Php is a loosely typed language so overloading by types won’t work, however overloading by number of parameters doesn’t work either.

It’s very nice sometimes in OOP to overload constructors so you can build the object in different ways (passing different number of arguments). A trick to do something like that in PHP is:

<?php

class Myclass {
   function Myclass() {
       $name=”Myclass”.func_num_args();
       $this->$name();
       //Note that $this->$name() is usually wrong but here
       //$name is a string with the name of the method to call.
   }

   function Myclass1($x) {
       code;
   }
   function Myclass2($x,$y) {
       code;
   }
}

?>

With this extra working in the class the use of the class is transparent to the user:

$obj1=new Myclass(‘1’); //Will call Myclass1
$obj2=new Myclass(‘1′,’2’); //Will call Myclass2

Sometimes this is very nice.


# Polymorphism

Polymorphism is defined as the ability of an object to determine which method to invoke for an object passed as argument in runtime time. For example if you have a class figure which defines a method draw and derived classes circle and rectangle where you override the method draw you might have a function which expects an argument x and then call $x->draw(). If you have polymorphism the method draw called depends of the type of object you pass to the function. Polymorphism is very easy and natural in interpreted languages as PHP (try to imagine a C++ compiler generating code for this case, which method do you call? You don’t know yet which type of object you have!, ok this is not the point). So PHP happily supports polymorphism.

<?php

function niceDrawing($x) {
   //Supose this is a method of the class Board.
   $x->draw();
}

$obj=new Circle(3,187);
$obj2=new Rectangle(4,5);

$board->niceDrawing($obj);    //will call the draw method of Circle.
$board->niceDrawing($obj2);   //will call the draw method of Rectangle.

?>


OOP programming in PHP
Some “purists” will say PHP is not truly an object oriented language, which is true. PHP is a hybrid language where you can use OOP and traditional procedural programming. For large projects, however, you might want/need(?) to use “pure” OOP in PHP declaring classes, and using only objects and classes for your project. As larger and larger projects emerge the use of OOP may help, OOP code is easy to mantain, easy to understand and easy to reuse. Those are the foundations of software engineering. Applying those concepts to web based projects is the key to success in future web sites.

Advanced OOP Techniques in PHP
After reviewing the basic concepts of OOP I can show you some more advanced techniques:


Serializing
PHP doesn’t support persistent objects, in OOP persistent objects are objects that keep its state and funcionality across multiple invocations of the application, this means having the ability of saving the object to a file or database and then loading the object back. The mechanism is known as serialization. PHP has a serialize method which can be called for objects, the serialize method returns a string representation of the object. However serialize saves the datamembers of the object but not the methods.

In PHP4 if you serialize the object to string $s, then destroy the object, and then unserialize the object to $obj you might still access the object methods! I don’t recommend this because (a) The documentation doesn’t guarrantee this beahaviour so in future versions it might not work. (b) This might lead to ‘illusions’ if you save the serialized version to disk and exit the script. In future runs of the script you can’t unserialize the string to an object an expect the methods to be there because the string representation doesn’t have the methods! Summarizing serializing in PHP is VERY useful to save the data members of an object just that. (You can serialize asociative arrays and arrays to save them to disk too).

Example: <?php

$obj=new Classfoo();
$str=serialize($obj);
// Save $str to disk

//…some months later

//Load str from disk
$obj2=unserialize($str)

?>

You have the datamembers recovered but not the methods (according to the documentation). This leads to $obj2->x as the only way to access the data members (you have no methods!) so don’t try this at home.

There’re some ways to fix the problem, I leave it up to you because they are too dirty for this neat article.

Full serialization is a feature I’d gladly welcome in PHP.

Using classes to manipulate stored data
One very nice thing of PHP and OOP is that you can easily define classes to manipulate certain things and the call the appropiate classes whenever you want. Suposse you have a html form where the user selects a product by selecting it’s product ID, you have the data of the products in a database and you want to display the product, show its price, etc etc. You have products of different types, and the same action might have different meanings for different kind of products. For example showing a sound might mean playing it while for some other kind of products might mean to display a picture stored in the database. You might use OOP and PHP to code less and code better:

Define a class product, define which methods the class should have (example display), then define classes for each type of product which extends the product class (class SoundItem, class ViewableItem, etc…) override the methods you define in product in each of this classes make them do what you want. Name the classes according to the “type” column you store in the database for each product a typical product table might have (id,type,price,description,etc etc)… Then in the processing script you can retrieve the type from the database and instanciate an object of the class named type using:

<?php

$obj=new $type();
$obj->action();

?>

This is a very nice feature of PHP, you might then call the display method of $obj or any other method regardless the type of object you have. With this technique you don’t have to touch the processing script when you add a new type of object, just add a class to handle it. This is quite powerful, just define the methods all objects regardless of its type should have, implement them in different ways in different classes and use them for any type of object in the main script, no ifs, no 2 programmers in the same file, eternal happiness. Do you agree programming is easy, mainteinance is cheaper and reusability is real now?

If you command a group of programmers is easy to divide the tasks, each one might be responsable for a type of object and the class that handles it. Internacionalization can be done using this technique, apply the proper class according to a language field selected by the user, etc.


Copying and cloning
When you create an object $obj you can copy the object by doing $obj2=$obj, the new object is a copy (not a reference) of $obj so it has the state $obj had in the moment the assignment was made. Sometimes you don’t want this, you just want to create a new object of the same class as obj, calling the constructor of the new object as if you had used the new statement. This can be done in PHP using serialization and a base class that all other classes must extend.


Entering a danger zone
When you serialize an object you get a string which has a certain format, you may investigate it if you are curious, one of the things the string has is the name of the class (nice!) you may extract it using:

<?php

$herring=serialize($obj);
$vec=explode(‘:’,$herring);
$nam=str_replace(“””,”,$vec[2]);

?>

So suposse you create a class “Universe” and force that all classes must extend universe, you can define a method clone in Universe as:

<?php

class Universe {
   function clone() {
       $herring=serialize($this);
       $vec=explode(‘:’,$herring);
       $nam=str_replace(“””,”,$vec[2]);
       $ret=new $nam;
       return $ret;
   }
}

//Then:

$obj=new Something();
   //Something extends Universe !!
$other=$obj->clone();

?>

What you get is a new object of class Something created the same way as using new, the constructor is called, etc. I don’t know if this is useful for you, but the Universe class which knows the name of the derived class is a nice concept to experiment. The only limit is your imagination.

Note: I’m using PHP4, something I write here may not work in PHP3.

HTML 긁어오는 프로그램 소스

Your first task is to create a Delphi function used to download a file from the Internet. One way of achieving this task is to use the WinInet API calls. Delphi gives us full access to the WinInet API (wininet.pas) which we can use to connect to and retrieve files from any Web site that uses either Hypertext Transfer Protocol (HTTP) or File Transfer Protocol (FTP). I’ve already written an article that describes this technique: Get File From the Net.

Another approach, if you have Delphi 6, is to use the TDownloadURL object. The TDownloadURL object, defined in ExtActns.pas unit, is designed for saving the contents of a specified URL to a file. Here’s the code that uses the TDownloadURL to download the “What’s New and Hot” page from this site.


uses extactns;  // <- must be added //

function Download_HTM(const sURL, sLocalFileName:string): boolean;
begin
Result:=True;
with TDownLoadURL.Create(nil) do
try
   URL:=sURL;
   Filename:=sLocalFileName;
   try
     ExecuteTarget(nil);
   except
     Result:=False
   end;
finally
   Free;
end;
end;





This function, Download_HTM, downloads a file from the URL specified in the sURL parameter, and saves this file locally under a sLocalFileName name. The function returns True if it succeeds, False otherwise. Of course, this function is to be called from the Button1 OnClick event handler. You can see the code below. Note that, locally, the file is saved as c: emp_adp.newandhot.

procedure TForm1.Button1Click(Sender: TObject);
const
ADPNEWHOTURL=’http://delphi.about.com/cs/newandhot/index.htm’;
TmpFileName=’c: emp_adp.newandhot’;
begin
if NOT Download_HTM(ADPNEWHOTURL,TmpFileName) then
begin
   ShowMessage(‘Error in HTML file download’);
   Exit;
end;

{
more code to be added
}

end;






Note: In the process of downloading a file, the TDownloadURL periodically generates an OnDownloadProgress event, so that you can provide users with feedback about the process. I’ll leave this for you to implement.

String Find Function (StrFnd)

특정 문자열을 찾아내 주는 소스.

델파이 프로그래밍 할 때마다 자주 애용하는 소스이다.
 

function StrFnd( source, key: String): Integer;
var
i, j, flen, slen, klen: Integer;
begin
slen := Length( source);
klen := Length( key);
flen := slen – klen + 1;

for i := 1 to flen do
begin
   if source[i]=key[1] then
   begin
     for j := 2 to klen do
     begin
       if source[i+j-1]<>key[j] then break;
     end;

     if j>klen then
     begin
       // the key is found on the source stream
       Result := i;
       exit;
     end;
   end;
end;

Result := -1;
end;

ActiveX에 다이얼로그 붙이기

ActiveX Control안에 다른 ActiveX Control을 올려놓을때는 차일드 속성외에..
app에 initinstance에서 AfxEnableControlContainer();를 호출해줘야 합니다..
예..
BOOL CClientApp::InitInstance()
{
BOOL bInit = COleControlModule::InitInstance();

if (bInit)
{
// TODO: Add your own module initialization code here.
AfxEnableControlContainer();
}

return bInit;
}
수고하세요.. 직장구하고 있음..^^ 난 초보..^^

[질문 내용]***********************************************
올린이 : 이승민

ActiveX Control에 child 속성의 다이얼로그를 하나 삽입한 후..
이에 관한 클래스를 새로 생성했습니다..
그런후 ActiveX Test Container로 테스트하면 다이얼로그 까지는 나오는데…
그 다이얼로그 위에…다른 ocx를 올려놓은후..
**Ctrl클래스의 OnCreate함수에
다이얼로그의 멤버변수.Create(생성한 다이얼로그 아이디,this);
그리구 같은 클래스의 OnDraw함수에
위저드가 생성한 코드를 지우고,
다이얼로그의 멤버변수.MoveWindow(rcBounds, TRUE);
를 하면..

다이얼로그의 멤버변수.MoveWindow(rcBounds, TRUE);
를 수행하면서 에러가 납니다…

그냥 MFC위저드로해보면 잘 되는데…왜그런건지..- -‘
ocx 내에 또 다른 ocx를 삽입하려면 주의해야할 점이 있나요..
꼭 가르쳐 주세요..

ListCtrl에서 아이템 추가하기 예제

char *strTitle, *strArtist, *strTime;

{
/* Add song information to play list */
LV_ITEM lvitem;

lvitem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE ;
//  lvitem.iImage = MemoryType – 1; /* Set Image Type */
lvitem.state =  0;
lvitem.stateMask = LVIS_DROPHILITED | LVIS_SELECTED | LVIS_FOCUSED;
lvitem.lParam = 0;

int intActualItemNumber;
CString strTemp, strNumber;

if (strArtist[0]!=’

ActiveX에서 바이너리 데이터 파라메터로 안깨지게 받는법

보통 LPCTSTR로 선언해서 쓰는데 그럼 가다가 end of string 이후가 깨져버린다.

그때 파라메터를 CHAR * 로 선언해서 쓰면된다.

Visual C++ 6.0에서는 CHAR* 선언이 불가능하므로 수동으로 고쳐주면된다.


이때 컨트롤 부분에서는 다음과 같은 부분도 수정해주어야 한다.
VTS_BSTR로 선언되어진 부분을 VTS_PI1로 선언해주면된다.

그러면 데이터 송수신시 깨지지 않는다.


from Control


DISP_FUNCTION(CKlientCtrl, “Send”, Send, VT_I2, VTS_BSTR VTS_I2)

EVENT_CUSTOM(“OnReceive”, FireOnReceive, VTS_BSTR  VTS_I4)

to

DISP_FUNCTION(CKlientCtrl, “Send”, Send, VT_I2, VTS_PI1 VTS_I2)

EVENT_CUSTOM(“OnReceive”, FireOnReceive, VTS_PI1 VTS_I4)

모달리스 다이얼로그의 종료 버튼을 클릭했을 때 종료가 안될때…

모달리스 다이얼로그의 종료 버튼을 클릭했을 때 종료가 안될때…


요로코롬 해보슈~



WndProc(..)
{
switch()
{
   case WM_SYSCOMMAND:
   {
     if(wParam==SC_CLOSE)
     {
       EndDialog();//종료
     }
   }
}





void CESTV2WDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else if (nID==SC_CLOSE)
{
   CDialog::OnCancel();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}