画像認証

画像認証基本 Pear(PHP)ファイル
img_auth_disp.php


63Pear Villageに戻る

<?php
// 必要パッケージの読込み
require_once ('Text/CAPTCHA.php');

// Text_CAPTCHAインスタンス作成
// のためパラメータ設定
$option = array(
  'width' => 240,
  'height' => 120,
// 認証画像の大きさをpx指定します。	
  'output' => 'png',
// 画像のファイル形式を指定します。

  'imageOptions' => array(
// フォントの指定
  'font_path' => 'fonts', //パス名
  'font_file' => 'cour.ttf',
// フォントは、C:\Windows\Fonts 
// からコピして
// fontsフォルダに置いてください。
// フォントサイズと色の指定	
  'font_size' => 24,
  'text_color' => '#CCEEDD',
// ラインの色設定		
  'lines_color' => '#CCEEDD',
// 背景色の設定		
  'background_color' => '#888888'
));
// インスタンスの作成
$captcha =
 Text_CAPTCHA::factory('Image');
// インスタンスを初期化
$captcha->init($option);
// 画像に表示させたフレーズの取得
$phrase = $captcha->getPhrase();

// 画像のバイナリデータを取得
$png = $captcha -> getCAPTCHA();
// $png =
//  $captcha -> getCAPTCHAAsPNG();
// と書いてある例が多いが動かない

// 取得画像を保存
file_put_contents
 ('img/auth_img.png', $png);
// PHP関数file_put_contents()
// により指定したパスと
// ファイル名でCAPTCHA画像を保存

echo"<img src='img/auth_img.png'>
  <br>";
echo $phrase;
// デバッグ用
?>