0
0

More than 3 years have passed since last update.

PHP ページにアクセスした時間の秒数で判定

Posted at

ページにアクセスした時間の秒が

00だった場合は「ジャストタイム!!」
00を除くゾロ目だった場合は「ゾロ目!」
上記以外の場合は「外れ」
という文字と秒を表示するプログラムを作成

<?php
$second = date("s");
?>
<!doctype html>
<html lang="ja">
    <head>
        <meta charset='utf-8'>
        <title>訪問時刻でif</title>
    </head>
    <body>
        <h1><?php echo date("Y/m/d H:i:s"); ?></h1>
<?php if($second === "00"){?>
        <h2>ジャストタイム!!</h2>
        <p>アクセスした瞬間の秒は00秒でした!!</p>
<?php } else if ($second === "11" || $second === "22" ||$second === "33" 
        || $second === "44" || $second === "55"){ ?>
        <h2>ゾロ目!</h2>
        <p>アクセスした瞬間の秒はゾロ目でした!</p>
<?php } else { ?>
        <h2>外れ</h2>
        <p>アクセスした瞬間の秒は<?php print $second; ?></p>  
s<?php } ?>
    </body>
</html>


ゾロ目の判定は他にやり方ないものですかね…

0
0
2

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
0