질문 Q #14045
codeigniter captcha helper
hassan 2016-07-02 13:50:45

제가 캡차를 만들려 하는데요 helper에 잇는 captcha를 쓸려고합니다

$vals = array(    'word' => 'Random word',    'img_path' => './captcha/',    'img_url' => 'http://example.com/captcha/',    'font_path' => './path/to/fonts/texb.ttf',    'img_width' => '150',    'img_height' => 30,    'expiration' => 7200    );$cap = create_captcha($vals);echo $cap['image'];

여기서 img_path와 img_url의 어떤것을 써줘야 되는 건가요?

답변 1
#1 배강민 2016-07-03 15:31:21

CI의 캡챠는 virtual로 그려내는게 아니라 실제 이미지 파일을 만들어냅니다.

img_path : 해당 이미지를 만들어낼 경로

img_url : 이미지의 실제 주소 

즉, 만약 해당 사이트의 root가 /home/public_html/ 이고, /home/public_public/captcha/ 경로를 이용할것이라면,

일단 당연히 captcha 폴더를 만드셔야하고,

img_path에 full path인 /home/public_html/captcha/ 또는 /home/public_html/ 에 index.php 가 있을테니 ./captcha/ 이면 됩니다.

그리고 메뉴얼에 써있는것과 같이 captcha 폴더에 쓰기 권한을 줘야하고,

img_url은 route 를 하지 않았다면 기본적으로는 http://www.com/captcha/이미지.확장자가 될테니

주소/captcha 정도를 쓰면 됩니다.

단, 이렇게 하면 해당 이미지 url에 브라우저가 접근이 되야하므로, mod_rewrite 에 captcha 경로를 써줘야합니다.

captcha 이미지용 가상(?) controller를 만든다면 상관은 없을수도 있겠고요.

해당 내용은 TapBBS 기준으로 application/controllers/user.php > join() 회원가입 부분에서 참고하실 수 있습니다.