A
A
apaicer2018-02-17 15:51:35
PHP
apaicer, 2018-02-17 15:51:35

Can't change the time zone in one of the .php pages?

Good afternoon! The problem is the following, I do not understand how to change the time zone on the page with notifications.
Now I will give an example with a chat, where the time zone works adequately + 4 hours. where is the $date variable, the string is called time in the database

<?php 

ULogin(1);
date_default_timezone_set('Europe/Samara');
$date = date("Y-m-d G:i:s");
if ($_POST['enter'] and $_POST['text']) {
$_POST['text'] = FormChars($_POST['text']);
mysqli_query($CONNECT, "INSERT INTO `chat`  VALUES ('', '$_POST[text]', '$_SESSION[USER_LOGIN]', '$date')");
exit(header('location: /chat'));

}

Head('Чат');
?>

Now the code that does not want to change the time zone. In the database, it is written as 0000000.
First, I registered it in index.php, that is, I took out the date before the start of the session. (I also set it before the start of the function)
<?php
date_default_timezone_set('Europe/Samara');
$date = date("Y-m-d G:i:s");
include_once 'setting.php';
session_start();

Then I wrote a function in the same file. Before $date was NOW(), but with it -4h
function SendNotice($p1, $p2) {
global $CONNECT;
$Row = mysqli_fetch_assoc(mysqli_query($CONNECT, "SELECT `id` FROM `users` WHERE `login` = '$p1'"));
if (!$Row['id']) echo 'Error';
mysqli_query($CONNECT, "INSERT INTO `notice` VALUES ('', '$Row[id]', 0, '$date', '$p2')");
}

I included the page and here is the code where the requests themselves occur. I throw only him, because. date doesn't appear anywhere else
if (!$Module or $Module == 'notice') {
$Param1 = "SELECT `id`, `status`, `date`, `text` FROM `notice` WHERE `uid` = $_SESSION[USER_ID] ORDER BY `id` DESC LIMIT 0, 5";
$Param2 = "SELECT `id`, `status`, `date`, `text` FROM `notice` WHERE `uid` = $_SESSION[USER_ID] ORDER BY `id` DESC LIMIT START, 5";
$Param3 = "SELECT COUNT(`id`) FROM `notice`";
$Param4 = "/notice/?page=";
}

And you know what's most interesting? If you write <?=date("Ymd G:i:s")?> in the futor, it shows the correct time zone!
In the database, date has type datetime

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question