0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

勉強メモ:作成したファンクション

Last updated at Posted at 2025-07-09

勉強中に作成したファンクションを備忘録的にまとめました。


ポストされた内容をチェックし、値によってステータスを変更するファンクション

予約ページなど受け渡す情報が多い場面で、ステータスによる条件分岐が行いやすく、管理もしやすいと感じた。
//入力項目のチェック
function checkloginid() {
    //配列の宣言
    $_SESSION['loginid'] = array();
    
    //POSTされた中身が空の時
    if($_REQUEST['loginid'] === ""){
        $_SESSION['loginid']['value'] = "";
        $_SESSION['loginid']['status'] = 1;
        
    //それ以外
    } else {
        $_SESSION['loginid']['value'] = $_REQUEST['loginid'];
        $_SESSION['loginid']['status'] = 0;
    }
}

指定ページ以外からの遷移時にはセッション情報を削除するファンクション

引数で正規表現にてURLを指定する。
//引数で指定したページ以外からの遷移ではセッションを削除する
function clearsession($address) {
    if ((!isset($_SESSION['url'])) || (preg_match($address,$_SESSION['url'])) === 0){
        unset($_SESSION['loginid']);
        unset($_SESSION['password']);
    }
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?