上記の画像のフォームで内容を送信したときの時間が、8時間ずれる現象が出ます。
PHP
1<?php 2 $link = mysqli_connect('localhost', 'root', ''); 3 if(!$link){ 4 die('cannot connect database: '.mysqli_error()); 5 } 6 7 mysqli_select_db($link,'online_bbs'); 8 9 $errors = array(); 10 11 if($_SERVER['REQUEST_METHOD'] === 'POST'){ 12 $name = null; 13 if(!isset($_POST['name']) || !strlen($_POST['name'])){ 14 $errors['name'] = 'Please write your name.'; 15 } else if(strlen($_POST['name']) > 40){ 16 $errors['name'] = 'Please write your name in 40.'; 17 } else { 18 $name = $_POST['name']; 19 } 20echo $_POST['name']."<br>"; 21 22 $comment = null; 23 if(!isset($_POST['comment']) || !strlen($_POST['comment'])){ 24 $errors['comment'] = 'Please write comment.'; 25 } else if(strlen($_POST['comment']) > 200){ 26 $errors['comment'] = 'Please write comment in 200.'; 27 } else{ 28 $comment = $_POST['comment']; 29 } 30 31echo $_POST['comment']; 32 33 if(count($errors) === 0){ 34 $sql = "insert into `post` (`name`, `comment`, `created_at`)"; 35 $sql .= "values('". mysqli_real_escape_string($link, $name)."',"; 36 $sql .= "'". mysqli_real_escape_string($link, $comment)."',"; 37 $sql .= "'". date('Y-m-d H:i:s')."')"; 38 39 mysqli_query($link, $sql); 40 } 41} 42 ?> 43 44<html lang="ja"> 45 <head> 46 <meta http-equiv="content-type" content="test/html" charset="utf-8"> 47 <title>BBS</title> 48 </head> 49 <body> 50 <h1>BBS</h1> 51 <form action="bbs.php" method="post"> 52 name: <input type="text" name="name"/><br/> 53 comment: <input type="text" name="comment" size="60"/><br/> 54 <input type="submit" name="submit" value="submit"> 55 </form> 56 </body> 57</html> 58
サーバ側での時刻はあっているけど、クライアント側で時間のずれが生じているみたいですが、考えられる原因は何でしょうか。
環境
Windows8.1
PHP 7.3.1
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。