function create_session($setup) { global $C, $I, $U, $db, $memcached; $U['nickname'] = preg_replace('/\\s+/', '', $_REQUEST['nick']); $U['passhash'] = md5(sha1(md5($U['nickname'] . $_REQUEST['pass']))); if (!check_member()) { add_user_defaults(); } $U['entry'] = $U['lastpost'] = time(); if ($setup) { $U['incognito'] = 1; } if (get_setting('captcha') > 0 && ($U['status'] == 1 || get_setting('dismemcaptcha') == 0)) { if (!isset($_REQUEST['challenge'])) { send_error($I['wrongcaptcha']); } if (!$C['memcached']) { $stmt = $db->prepare("SELECT code FROM {$C['prefix']}captcha WHERE id=?;"); $stmt->execute(array($_REQUEST['challenge'])); $stmt->bindColumn(1, $code); if (!$stmt->fetch(PDO::FETCH_BOUND)) { send_error($I['captchaexpire']); } $timeout = time() - get_setting('captchatime'); $stmt = $db->prepare("DELETE FROM {$C['prefix']}captcha WHERE id=? OR time<?;"); $stmt->execute(array($_REQUEST['challenge'], $timeout)); } else { if (!($code = $memcached->get("{$C['dbname']}-{$C['prefix']}captcha-{$_REQUEST['challenge']}"))) { send_error($I['captchaexpire']); } $memcached->delete("{$C['dbname']}-{$C['prefix']}captcha-{$_REQUEST['challenge']}"); } if ($_REQUEST['captcha'] != $code) { send_error($I['wrongcaptcha']); } } if ($U['status'] == 1) { $ga = (int) get_setting('guestaccess'); if (!valid_nick($U['nickname'])) { send_error(sprintf($I['invalnick'], get_setting('maxname'))); } if (!valid_pass($_REQUEST['pass'])) { send_error(sprintf($I['invalpass'], get_setting('minpass'))); } if ($ga === 0) { send_error($I['noguests']); } elseif ($ga === 3) { $U['entry'] = 0; } if (get_setting('englobalpass') != 0 && isset($_REQUEST['globalpass']) && $_REQUEST['globalpass'] != get_setting('globalpass')) { send_error($I['wrongglobalpass']); } } write_new_session(); }
<?php // Chapter2 PHPの基礎 Section25 引数 // 引数にデフォルト値を設定する // $user = "******"; // $pass = "******"; // check_member($user,$pass); check_member(); // 【 デフォルト値の指定の順番 】 // デフォルト値を複数指定する場合、 // デフォルト値を指定した引数の右側に、 // デフォルト値を指定しない引数があるとエラーよりもあとになる。 function check_member($username = "******", $password = "******") { if ($username == "guest" && $password == "guest") { print "ゲストさん、ようこそ!"; } else { print "会員さん、ようこそ!"; } }