Programming/php2017. 1. 6. 08:59

예제를 찾아보니 session_start()는 당연한건데..

$_SESSION 에서 사용하는 로그인 플래그 등을 없애는 식으로 로그아웃을 구현한것들도 보인다.

그냥 세션정보 자체를 파괴해버리면 간단하지 않을려나? 무슨 이유가 있을까?


[링크 : http://php.net/manual/kr/function.session-start.php]

[링크 : http://php.net/manual/kr/function.session-destroy.php]

'Programming > php' 카테고리의 다른 글

php <?=$var>  (0) 2017.01.09
PHP 최적화 관련  (0) 2017.01.09
php pack / unpack  (0) 2017.01.04
php foreach / array  (0) 2017.01.03
php "str"과 'str' 차이점  (2) 2017.01.03
Posted by 구차니

여기 문서를 참고해서 일단

가입 - 인증서 설치 - 로그인 - domain 인증 - 사이트 인증서 발급 함

[링크 : https://www.xetown.com/slope/135905]


발급과정에서 개인키 생성해서 웹에붙여 주어야 하는데 yourname.csr을 사용하고

개인키에 암호를 삭제한 yourname.nokey 파일을 생성

$ openssl req -newkey rsa:2048 -keyout yourname.key -out yourname.csr

Generating a 2048 bit RSA private key

.+++

.....................+++

writing new private key to 'yourname.key'

Enter PEM pass phrase:

Verifying - Enter PEM pass phrase:

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [AU]:KR

State or Province Name (full name) [Some-State]:

Locality Name (eg, city) []:

Organization Name (eg, company) [Internet Widgits Pty Ltd]:

Organizational Unit Name (eg, section) []:

Common Name (e.g. server FQDN or YOUR name) []:

Email Address []:


Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:


그리고는 키를 없애고 키 저장소로 복사!

$ openssl rsa -in yourname.key -out yourname.nokey

Enter pass phrase for yourname.key:

writing RSA key

$ sudo cp yourname.nokey /etc/ssl/private/yourname.nokey 

[링크 : http://blog.acu.pe.kr/55]


그러면 zip파일로 다운받을 수 있는데

apache를 쓰고 있으니 해당 파일을 압축 풀어 /etc/ssl/certs 에 넣어 주었다.

$ unzip minimonk.net.zip

$ unzip ApacheServer.zip

$ sudo cp *.crt /etc/ssl/certs


일단 공식사이트에서는 이렇게 하라는데

SSLCertificateFile "/usr/local/apache2/conf/2_your_domain.crt"

SSLCertificateKeyFile "/usr/local/apache2/conf/private.key"

SSLCertificateChainFile "/usr/local/apache2/conf/1_root_bundle.crt" 

[링크 : https://www.startssl.com/Support?v=21]


나의 경우에는 이런식으로 설정

$ sudo vi /etc/apache2/sites-available/default-ssl.conf 

                SSLCertificateFile /etc/ssl/certs/2_your_domain.crt

                SSLCertificateKeyFile /etc/ssl/private/yourname.nokey

                SSLCertificateChainFile /etc/ssl/certs/1_root_bundle.crt


아무튼 라즈베리 키로 할때는 안전하지 않음이라고 크롬에서 뜨는데

starssl 에서 적용하니 이제 안전함! 우오오옹

class 1이라 그런가

은행권 처럼 녹색으로 줄이 쫙! 그이진 않네


---

처음 하라는대로 해보니 되긴한데 암호 넣으라고 한다. ㅠㅠ

그래서 키삭제 하는게 서비스 유지에는 편리!

$ sudo service apache2 restart

Enter passphrase for SSL/TLS keys for 127.0.1.1:443 (RSA): ******** 



어? 아이패드에서 (ios 10.2) 접속 자체를 안하는것 같다?!?!
[링크 : https://discussions.apple.com/thread/7791706?start=0&tstart=0]


Posted by 구차니

라즈베리 파이에서 매일매일 logrotate 하도록 하고

webalizer는 access.log.1 을 보도록 되어 있어서

logrotate를 안돌리면 webalizer 쪽이 갱신되지 않는 문제가 있다.


아무튼 몇일되는 바람에 .3 까지 생겨서

이렇게 하나로 묶어주고 실행해서 업데이트!

$ sudo su -

# cd /var/log/apache2

# cat access.log.3 access.log.2 access.log.1 access.log > access.log.all 

# rm access.log

# mv access.log.all access.log

# vi /etc/webalizer/webalizer.conf

LogFile /var/log/apache2/access.log

# webalizer


Posted by 구차니

예전 db 수업 시간에 들은거 같은데

결론은.. 다대다 관계를 지원하더라도 되도록이면 DB정규화를 통해

1:N이나 N:1으로 다대다 관계를 풀어서 쓰도록


[링크 : http://loopypapa.tistory.com/entry/SQL-일대일-일대다-다대다-관계]

[링크 : http://www.taeyo.net/Forum/Content.aspx?SEQ=22495&TBL=SQL&PGN=1330]

Posted by 구차니
Linux/Ubuntu2017. 1. 4. 15:11

일단.. crontab 파일이 바뀌면 자동으로 읽어 들이지만..

logrotate의 경우 는 crontab 파일에 있는게 아니니.. 다시 읽어 들이지 않으려나?

아니면 내가 설정을 잘못해서 apache 로그가 daily에서 monthly로 바꾼게 적용되지 않았던 걸까?


[링크 : http://stackoverflow.com/questions/10193788/restarting-cron-after-changing-crontab-file]

[링크 : http://unix.stackexchange.com/questions/116136/how-to-make-log-rotate-change-take-effect]


생각해 보니까.. /etc/cron.daily에 있으니 맨날 실행되겠...지? 설정이 monthly라도?

[링크 : http://blueskai.tistory.com/101]

Posted by 구차니

외래키는 어떻게 보면.. 자동으로 연관항목 삭제시 같이 삭제하도록 하는 "자동화"에 가까운 느낌

삭제가 아니더라도 null 값으로 바꾼다던가 하는 일종의 trigger라고 해야하나?

[링크 : http://zetawiki.com/wiki/MySQL_외래키_생성]

[링크 : http://cloudless.tistory.com/49]


MyISAM DB 타입일 경우 도움 외래키 지원을 안해서 그걸 지원해주는 용도라니까.. 딱히 안써도 될 듯

[링크 : http://stackoverflow.com/.../difference-between-mysql-foreign-key-and-internal-relation]


[링크 : http://stackoverflow.com/.../what-are-the-internal-relations-defined-in-phpmyadmin]

[링크 : http://stackoverflow.com/.../what-do-internal-relations-do-in-phpmyadmin-for-myisam-tables]


db 타입이 MyISAM 일 경우에는 외래키를 지원하지 않고, InnoDB로 해야지 지원을 하게 된다.

[링크 : http://ojava.tistory.com/25]

[링크 : http://codeigniter-kr.org/bbs/view/tip?idx=8348]


[링크 : http://egloos.zum.com/mcchae/v/10625121]

[링크 : http://jason-heo.github.io/mysql/2014/03/05/mysql-foreign-key.html]

Posted by 구차니

phpmyadmin 에서 인덱스가 없습니다! 하나 생성하세요.

라고 하길래 봤는데.. 이거 막 새엇ㅇ하면 안되겠꾸만


인덱스 생성시 느리고, select시 성능향상을 줌

[링크 : http://ra2kstar.tistory.com/96]


oracle과 차이점

[링크 : http://gywn.net/2012/05/mysql-bad-sql-type/]


null 대신 not null(그래서 기본값이 not null 이었나..)

[링크 : http://egloos.zum.com/tiger5net/v/5660848]


https://blog.lael.be/post/370

'프로그램 사용 > mysql & mariaDB' 카테고리의 다른 글

mysql 변수별 사이즈  (0) 2017.01.12
mysql 다대다 관계  (0) 2017.01.04
mysql datetime과 timestamp 차이점  (0) 2017.01.04
mysqldump 복구시 TYPE=MyISAM 오류  (0) 2016.10.06
woobi mysql 백업복구  (0) 2015.03.02
Posted by 구차니

phpmyadmin에서 작업을 하는데

Null no가 떠서 먼가 하고 보는 중인데..

mysql client에서 보면.. Null 은 no 똑같네?

mysql> desc archlog_useraccount;l

+----------------+-------------+------+-----+---------+----------------+

| Field          | Type        | Null | Key | Default | Extra          |

+----------------+-------------+------+-----+---------+----------------+

| idx            | int(11)     | NO   | PRI | NULL    | auto_increment |

| time_create    | datetime    | NO   |     | NULL    |                |

| time_lastlogin | datetime    | NO   |     | NULL    |                |

| time_lastmodi  | datetime    | NO   |     | NULL    |                |

| userid         | char(50)    | NO   |     | NULL    |                |

| passwd         | char(72)    | NO   |     | NULL    |                |

| passwd_plain   | char(12)    | NO   |     | NULL    |                |

| username       | varchar(30) | NO   |     | NULL    |                |

| birth          | datetime    | NO   |     | NULL    |                |

+----------------+-------------+------+-----+---------+----------------+

9 rows in set (0.01 sec)


아무튼.. 덤프해서 보면 alter로 속성값 바꾸듯 해두었는데

CREATE TABLE IF NOT EXISTS `archlog_useraccount` (

`idx` int(11) NOT NULL,

  `time_create` datetime NOT NULL,

  `time_lastlogin` datetime NOT NULL,

  `time_lastmodi` datetime NOT NULL,

  `userid` char(50) NOT NULL,

  `passwd` char(72) NOT NULL,

  `passwd_plain` char(12) NOT NULL,

  `username` varchar(30) NOT NULL,

  `birth` datetime NOT NULL

) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='user account table';


ALTER TABLE `archlog_useraccount`

 ADD PRIMARY KEY (`idx`), ADD UNIQUE KEY `idx` (`idx`,`userid`);


ALTER TABLE `archlog_useraccount`

MODIFY `idx` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2;


예제를 보면 이런식으로 생성시에 넣을수 있는 듯

CREATE TABLE animals (

    grp ENUM('fish','mammal','bird') NOT NULL,

    id MEDIUMINT NOT NULL AUTO_INCREMENT,

    name CHAR(30) NOT NULL,

    PRIMARY KEY (grp,id)

) ENGINE=MyISAM; 


[링크 : http://dev.mysql.com/doc/refman/5.7/en/example-auto-increment.html]



그리고 null / no는 not null이 맞는 듯

그런데 pri키로서 idx는 null이 넣어도 에러 안나던데 !!?


자세히 보니.. NULL은 아니고 ''로 빈 문자열을 넣어 버렸네 -_-


Posted by 구차니

mysql 5.7 메뉴얼인데.. 1970 epoch 기준으로 timestamp를 사용되는데 32bit 인가..

mysql 64bit면 더 길게 저장이 되려나?



아무튼 차이점은 timestamp는 UTC + epoch(2038년 문제 발생)

datetime은 9999년까지 가능


The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.


The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC

[링크 : http://dev.mysql.com/doc/refman/5.7/en/datetime.html]


8바이트 먹지만 DATETIME형을 쓰는게 2038 문제 회피에 유리하다 인가?

[링크 : http://stackoverflow.com/questions/2012589/php-mysql-year-2038-bug-what-is-it-how-to-solve-it]


[링크 : http://mysqldba.tistory.com/268]

[링크 : http://blog.naver.com/gigar/60115731039]

[링크 : http://linux.systemv.pe.kr/timestamp-datetime-기능-개선/]


DATETIME에는 NOW() 함수로 현재 시간을 넣어 줄 수 있네

[링크 : http://jsonobject.tistory.com/122]

Posted by 구차니
Programming/php2017. 1. 4. 09:21

문구를 보는데 이게 먼가 싶은데..

일단 XN[NAME] 으로 X는 타입 N은 자릿수 인거고 뒤에는 array의 key값이 되는 듯?


array unpack ( string $format , string $data )

string pack ( string $format [, mixed $args [, mixed $... ]] )

[링크 : http://php.net/manual/en/function.unpack.php]


format

The format string consists of format codes followed by an optional repeater argument. The repeater argument can be either an integer value or * for repeating to the end of the input data. For a, A, h, H the repeat count specifies how many characters of one data argument are taken, for @ it is the absolute position where to put the next data, for everything else the repeat count specifies how many data arguments are consumed and packed into the resulting binary string.

[링크 : http://php.net/manual/en/function.pack.php]

[링크 : http://www.w3schools.com/php/func_misc_unpack.asp]


+

2017.01.06

"C*"은 그럼 singed char를 무한반복해서 unpack 하라는 의미였고

"i1"은 signed integer를 1번 만 하라는 의미였군

'Programming > php' 카테고리의 다른 글

PHP 최적화 관련  (0) 2017.01.09
php 로그인 관련 - 세션  (0) 2017.01.06
php foreach / array  (0) 2017.01.03
php "str"과 'str' 차이점  (2) 2017.01.03
php class 그리고.. 구조체가 없다?  (0) 2017.01.02
Posted by 구차니