「php」タグアーカイブ

メールのパスワードの設定プログラム

メールのパスワード設定一覧を作るときに半角英数で、メールアドレスが有効で、メールアドレスとは別にアカウントがあります。

いろんなチェックをして、生成して、配らないといけません。結構面倒ですし、エラーも多いので、こちらでプログラムを書いてみました。

追加仕様:(2名様のニーズを反映)
1.必ず英字大文字小文字数字記号の組み合わせを入れる。
2.10桁から12桁までランダム

サンプルプログラムは下記になります。CSV形式等は自分で行なってください。

https://abundcore.net/program-library/email-password/

 

<?php

function generateRandomPassword() {
    // パスワードの長さを10から12桁の間でランダムに決定
    $length = rand(10, 12);
    // 各カテゴリの文字
    $lowercaseLetters = 'abcdefghijklmnopqrstuvwxyz';
    $uppercaseLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $numbers = '0123456789';
    $symbols = '#%=-+:?_<>[]{}()^!,.';

    // 各カテゴリから最低1文字を確実に含める
    $password = $lowercaseLetters[rand(0, strlen($lowercaseLetters) - 1)];
    $password .= $uppercaseLetters[rand(0, strlen($uppercaseLetters) - 1)];
    $password .= $numbers[rand(0, strlen($numbers) - 1)];
    $password .= $symbols[rand(0, strlen($symbols) - 1)];

    // 全ての文字を結合して残りの部分をランダムに選択
    $allCharacters = $lowercaseLetters . $uppercaseLetters . $numbers . $symbols;
    for ($i = strlen($password); $i < $length; $i++) {
        $password .= $allCharacters[rand(0, strlen($allCharacters) - 1)];
    }

    // パスワードをシャッフルして各カテゴリの文字が最初に来ないようにする
    $password = str_shuffle($password);

    return $password;
}

function isValidUsername($username) {
    // ユーザーネームが半角英数とピリオド、ハイフンのみを含むかチェック
    return $username !== '' && preg_match('/^[a-zA-Z0-9\.\-]+$/', $username);
}

function isValidEmail($email) {
    return $email !== '' && filter_var($email, FILTER_VALIDATE_EMAIL);
}

$userData = [];
$errors = [];

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    for ($i = 1; $i <= 5; $i++) {
        $username = $_POST["username$i"] ?? '';
        $email = $_POST["email$i"] ?? '';
        if ($username !== '' || $email !== '') {
            if (!isValidUsername($username)) {
                $errors[] = "ユーザーアカウント {$i} は無効です。半角英数とピリオド、ハイフンのみ使用可能です。";
                continue;
            }
            if (!isValidEmail($email)) {
                $errors[] = "メールアドレス {$i} は無効です。";
                continue;
            }
            $password = generateRandomPassword();
            $userData[] = [
                'username' => $username,
                'email' => $email,
                'password' => $password
            ];
        }
    }
}
?>

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>パスワードフォーム</title>
</head>
<body>
    <h1>パスワードフォーム</h1>
    <form method="post">
        <?php for ($i = 1; $i <= 5; $i++): ?>
            <div>
                <label for="username<?= $i ?>">ユーザーアカウント <?= $i ?>:</label>
                <input type="text" id="username<?= $i ?>" name="username<?= $i ?>">
                <label for="email<?= $i ?>">メールアドレス:</label>
                <input type="email" id="email<?= $i ?>" name="email<?= $i ?>">
            </div>
        <?php endfor; ?>
        <button type="submit">送信</button>
    </form>
    
    <?php if (!empty($errors)): ?>
        <div style="color: red;">
            <?php foreach ($errors as $error): ?>
                <p><?= $error ?></p>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>

    <?php if (!empty($userData)): ?>
        <h2>生成されたパスワード一覧</h2>
        <table border="1">
            <tr>
                <th>ユーザーアカウント</th>
                <th>メールアドレス</th>
                <th>新しいパスワード</th>
            </tr>
            <?php foreach ($userData as $user): ?>
                <tr>
                    <td><?= htmlspecialchars($user['username'], ENT_QUOTES) ?></td>
                    <td><?= htmlspecialchars($user['email'], ENT_QUOTES) ?></td>
                    <td><?= $user['password'] ?></td>
                </tr>
            <?php endforeach; ?>
        </table>
    <?php endif; ?>
</body>
</html>

MantisBT 2.24.1 でインストールで文字化け

バグ管理システムMantisBT 2.24.1で順調インストールでしたと思ったら、「検索」や「マイビュー」で文字化け。
一瞬「Warning: 2702 in *****/core/session_api.php on line 227」のエラーがでて、すぐに文字化けしたり、
そのまま文字化けの画面だったり。
文字化け

対応方法、MantisBTをインストールしたディレクトリに
.htaccess ファイルを配置してください。
下記の内容を追記:

#PHP
php_value output_handler none

これで直ると思います。

https://mantisbt.org/

EC-CUBE 管理者メニュー 権限設定について

注意:自己責任でお願い致します。

EC-CUBE の管理画面では

ログイン者ごとに権限を設定できる仕様になっています。

現在のところ、権限ごとに画面を制御するのではなく、

管理者メニューの項目を権限によって非表示することで

簡易的な制御をしています。

(この経緯は、EC-CUBEのコミュニティーサイトで議論されており

設定方法も、コミュニティサイトにのっています)

http://xoops.ec-cube.net/modules/newbb/viewtopic.php?viewmode=flat&order=ASC&topic_id=398&forum=7

今回、権限を4種類ほど設定して権限ごとにメニュー項目の表示非表示をするにあたり

メニュー項目の設定の一覧を作成しました。

 

その際に、

data/Smarty/templates/admin/design/subnavi.tpl

を修正いたしました。

修正内容は以下のとおりです。


<ul>
<li id="navi-design-pc"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/<!--{$smarty.const.DIR_INDEX_PATH}-->?device_type_id=<!--{$smarty.const.DEVICE_TYPE_PC}-->"><span>PC</span></a>
<ul>
<li<!--{if $tpl_subno == 'layout'}--><!--{/if}--> id="navi-design-pc-layout"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/<!--{$smarty.const.DIR_INDEX_PATH}-->?device_type_id=<!--{$smarty.const.DEVICE_TYPE_PC}-->"><span>レイアウト設定</span></a></li>
<li<!--{if $tpl_subno == 'main_edit'}--><!--{/if}--> id="navi-design-pc-main"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/main_edit.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_PC}-->"><span>ページ詳細設定</span></a></li>
<li<!--{if $tpl_subno == 'bloc'}--><!--{/if}--> id="navi-design-pc-bloc"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/bloc.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_PC}-->"><span>ブロック設定</span></a></li>
<li<!--{if $tpl_subno == 'header'}--><!--{/if}--> id="navi-design-pc-header"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/header.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_PC}-->"><span>ヘッダー/フッター設定</span></a></li>
<li<!--{if $tpl_subno == 'css'}--><!--{/if}--> id="navi-design-pc-css"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/css.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_PC}-->"><span>CSS設定</span></a></li>
<li<!--{if $tpl_subno == 'template'}--><!--{/if}--> id="navi-design-pc-template"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/template.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_PC}-->"><span>テンプレート設定</span></a></li>
<li<!--{if $tpl_subno == 'up_down'}--><!--{/if}--> id="navi-design-pc-add"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/up_down.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_PC}-->"><span>テンプレート追加</span></a></li>
</ul>
</li>
<li id="navi-design-mobile"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/<!--{$smarty.const.DIR_INDEX_PATH}-->?device_type_id=<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><span>モバイル</span></a>
<ul>
<li<!--{if $tpl_subno == 'layout'}--><!--{/if}--> id="navi-design-mobile-layout-<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/<!--{$smarty.const.DIR_INDEX_PATH}-->?device_type_id=<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><span>レイアウト設定</span></a></li>
<li<!--{if $tpl_subno == 'main_edit'}--><!--{/if}--> id="navi-design-mobile-main-<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/main_edit.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><span>ページ詳細設定</span></a></li>
<li<!--{if $tpl_subno == 'bloc'}--><!--{/if}--> id="navi-design-mobile-bloc-<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/bloc.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><span>ブロック設定</span></a></li>
<li<!--{if $tpl_subno == 'header'}--><!--{/if}--> id="navi-design-mobile-header-<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/header.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><span>ヘッダー/フッター設定</span></a></li>
<li<!--{if $tpl_subno == 'css'}--><!--{/if}--> id="navi-design-mobile-css-<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/css.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><span>CSS設定</span></a></li>
<li<!--{if $tpl_subno == 'template'}--><!--{/if}--> id="navi-design-mobile-template-<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/template.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><span>テンプレート設定</span></a></li>
<li<!--{if $tpl_subno == 'up_down'}--><!--{/if}--> id="navi-design-mobile-add-<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/up_down.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_MOBILE}-->"><span>テンプレート追加</span></a></li>
</ul>
</li>
<li id="navi-design-sphone"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/<!--{$smarty.const.DIR_INDEX_PATH}-->?device_type_id=<!--{$smarty.const.DEVICE_TYPE_SMARTPHONE}-->"><span>スマートフォン</span></a>
<ul>
<li<!--{if $tpl_subno == 'layout'}--><!--{/if}--> id="navi-design-sphone-layout"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/<!--{$smarty.const.DIR_INDEX_PATH}-->?device_type_id=<!--{$smarty.const.DEVICE_TYPE_SMARTPHONE}-->"><span>レイアウト設定</span></a></li>
<li<!--{if $tpl_subno == 'main_edit'}--><!--{/if}--> id="navi-design-sphone-main"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/main_edit.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_SMARTPHONE}-->"><span>ページ詳細設定</span></a></li>
<li<!--{if $tpl_subno == 'bloc'}--><!--{/if}--> id="navi-design-sphone-bloc"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/bloc.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_SMARTPHONE}-->"><span>ブロック設定</span></a></li>
<li<!--{if $tpl_subno == 'header'}--><!--{/if}--> id="navi-design-sphone-header"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/header.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_SMARTPHONE}-->"><span>ヘッダー/フッター設定</span></a></li>
<li<!--{if $tpl_subno == 'css'}--><!--{/if}--> id="navi-design-sphone-css"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/css.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_SMARTPHONE}-->"><span>CSS設定</span></a></li>
<li<!--{if $tpl_subno == 'template'}--><!--{/if}--> id="navi-design-sphone-template"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/template.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_SMARTPHONE}-->"><span>テンプレート設定</span></a></li>
<li<!--{if $tpl_subno == 'up_down'}--><!--{/if}--> id="navi-design-sphone-add"><a href="<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->design/up_down.php?device_type_id=<!--{$smarty.const.DEVICE_TYPE_SMARTPHONE}-->"><span>テンプレート追加</span></a></li>
</ul>
</li>
</ul>

書き換え部分は <… id=’navi-******’ …> の部分のみです。

検証は2.11.4で行いました。

以下はcssに設定が簡単に出来るようにまとめたものです。


/*  管理者メニュー id一覧                                                     */
/*  管理者の権限番号毎にcssに設定することによりメニューを非表示に出来る       */
/*  デザイン部分サブメニューのidの設定については、                            */
/*  data/Smarty/templates/admin/design/subnavi.tpl書き換えを行っているため、  */
/*  一部既存のものと対応していない                                            */
/*  authority_* の*部分には権限番号を設定すること                             */
/*  権限番号については、mtb_authorityを参照                                   */
/*  cssファイルは html/user_data/packages/admin/css/admin_contents.css        */
/*  cssの設定を行ってメニューの非表示が出来るだけである                       */
/*  管理画面ログイン後、直接urlを指定した場合はその画面を操作できます         */

,.authority_* #navi-basis                   /* 基本情報管理             */
,.authority_* #navi-basis-index             /* -SHOPマスター           */
,.authority_* #navi-basis-tradelaw          /* -特定商取引法           */
,.authority_* #navi-basis-delivery          /* -配送方法設定           */
,.authority_* #navi-basis-payment           /* -支払方法設定           */
,.authority_* #navi-basis-point             /* -ポイント設定           */
,.authority_* #navi-basis-mail              /* -メール設定             */
,.authority_* #navi-basis-seo               /* -SEO管理                */
,.authority_* #navi-basis-kiyaku            /* -会員規約設定           */
,.authority_* #navi-basis-zip               /* -郵便番号DB登録         */
,.authority_* #navi-basis-holiday           /* -定休日管理             */

,.authority_* #navi-customer                /* 顧客管理                 */
,.authority_* #navi-customer-index          /* -顧客マスター           */
,.authority_* #navi-customer-customer       /* -顧客登録               */

,.authority_* #navi-order                   /* 受注管理                 */
,.authority_* #navi-order-index             /* -受注管理               */
,.authority_* #navi-order-add               /* -受注登録               */
,.authority_* #navi-order-status            /* -対応状況管理           */

,.authority_* #navi-products                /* 商品管理                 */
,.authority_* #navi-products-index          /* -商品マスター           */
,.authority_* #navi-products-product        /* -商品登録               */
,.authority_* #navi-products-uploadcsv      /* -商品登録CSV            */
,.authority_* #navi-products-class          /* -規格管理               */
,.authority_* #navi-products-category       /* -カテゴリー登録         */
,.authority_* #navi-products-category       /* -カテゴリー登録CSV      */
,.authority_* #navi-products-maker          /* -メーカー登録           */
,.authority_* #navi-products-rank           /* -商品並び替え           */
,.authority_* #navi-products-review         /* -レビュー管理           */

,.authority_* #navi-total                   /* 売上集計                 */
,.authority_* #navi-total-term              /* -期間別集計             */
,.authority_* #navi-total-products          /* -商品別集計             */
,.authority_* #navi-total-age               /* -年代別集計             */
,.authority_* #navi-total-job               /* -職業別集計             */
,.authority_* #navi-total-member            /* -会員別集計             */

,.authority_* #navi-mail                    /* メルマガ管理             */
,.authority_* #navi-mail-index              /* -配信内容設定           */
,.authority_* #navi-mail-template           /* -テンプレート設定       */
,.authority_* #navi-mail-history            /* -配信履歴               */

,.authority_* #navi-contents                /* コンテンツ管理           */
,.authority_* #navi-contents-index          /* -新着情報管理           */
,.authority_* #navi-contents-recommend      /* -おすすめ商品管理       */
,.authority_* #navi-contents-file           /* -ファイル管理           */
,.authority_* #navi-contents-csv            /* -CSV出力項目設定        */
,.authority_* #navi-csv-product             /* |-商品管理              */
,.authority_* #navi-csv-customer            /* |-会員管理              */
,.authority_* #navi-csv-order               /* |-受注管理              */
,.authority_* #navi-csv-category            /* |-カテゴリ              */
,.authority_* #navi-csv-review              /* |-レビュー              */
,.authority_* #navi-csv-sql                 /* |-高度な設定            */

,.authority_* #navi-design                  /* デザイン管理             */
,.authority_* #navi-design-pc               /* -PC (id 追加)                    */
,.authority_* #navi-design-pc-layout        /* |-レイアウト設定(id 修正)        */
,.authority_* #navi-design-pc-main          /* |-ページ詳細設定(id 修正)        */
,.authority_* #navi-design-pc-bloc          /* |-ブロック設定(id 修正)          */
,.authority_* #navi-design-pc-header        /* |-ヘッダー/フッター設定(id 修正) */
,.authority_* #navi-design-pc-css           /* |-CSS設定(id 修正)               */
,.authority_* #navi-design-pc-template      /* |-テンプレート設定(id 修正)      */
,.authority_* #navi-design-pc-add           /* |-テンプレート追加(id 修正)      */
,.authority_* #navi-design-mobile           /* -モバイル(id 追加)               */
,.authority_* #navi-design-mobile-layout    /* |-レイアウト設定(id 修正)        */
,.authority_* #navi-design-mobile-main      /* |-ページ詳細設定(id 修正)        */
,.authority_* #navi-design-mobile-bloc      /* |-ブロック設定(id 修正)          */
,.authority_* #navi-design-mobile-header    /* |-ヘッダー/フッター設定(id 修正) */
,.authority_* #navi-design-mobile-css       /* |-CSS設定(id 修正)               */
,.authority_* #navi-design-mobile-template  /* |-テンプレート設定(id 修正)      */
,.authority_* #navi-design-mobile-add       /* |-テンプレート追加(id 修正)      */
,.authority_* #navi-design-sphone           /* -スマートフォン(id 追加)         */
,.authority_* #navi-design-sphone-layout    /* |-レイアウト設定(id 修正)        */
,.authority_* #navi-design-sphone-main      /* |-ページ詳細設定(id 修正)        */
,.authority_* #navi-design-sphone-bloc      /* |-ブロック設定(id 修正)          */
,.authority_* #navi-design-sphone-header    /* |-ヘッダー/フッター設定(id 修正) */
,.authority_* #navi-design-sphone-css       /* |-CSS設定(id 修正)               */
,.authority_* #navi-design-sphone-template  /* |-テンプレート設定(id 修正)      */
,.authority_* #navi-design-sphone-add       /* |-テンプレート追加(id 修正)      */
,.authority_* #navi-system                  /* システム設定             */

,.authority_* #navi-system-index            /* -メンバー管理           */
,.authority_* #navi-system-bkup             /* -バックアップ管理       */
,.authority_* #navi-system-parameter        /* -パラメーター設定       */
,.authority_* #navi-system-masterdata       /* -マスターデータ管理     */
,.authority_* #navi-system-adminarea        /* -管理画面設定           */
,.authority_* #navi-system-system           /* -システム情報           */
,.authority_* #navi-system-plugin           /* -プラグイン管理         */
,.authority_* #navi-system-log              /* -EC-CUBE ログ表示       */
,.authority_* #navi-system-editdb           /* -高度なデータベース管理 */

,.authority_* #navi-ownersstore             /* オーナーズストア         */
,.authority_* #navi-ownersstore-index       /* -購入商品一覧           */
,.authority_* #navi-ownersstore-settings    /* -認証キー設定           */
,.authority_* #navi-ownersstore-log         /* -ログ管理               */

使用方法についての詳細はまた。

phpize でAUTOCONFエラー

# phpize
phpize(phpの拡張モジュールのためのビルドツール)で
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
というエラーが出たら、

CentOSなどなら、単純に
# yum install autoconf
をするだけで解決する場合があります。
自己責任です。解決しない場合はバス等の間違えがあります。

PHPのプラグイン開発で不思議なエラー

WordPressなどのプラグイン開発をしていて、「Cannot modify header information – headers already sent by」というエラーが出たら、ヘッダー処理のエラーなのですけど、エラーの指定行もなにもしていないのに・・・という場合。

プラグインのファイルに<?php ・・・・?>の上下にゴミ改行が入っているだけでこのエラーが出ます。

確認してみてください。他にもエラーになる要素はありますが、プラグイン化する前に

普通に動いていた場合はここを確認。

株式会社アバンドでは、WordPressなどのCMSツールを使った中規模から大規模までのWeb構築を行っております。

まずは、お気軽にお問い合わせください。