简体   繁体   中英

PHP don't update time

I made php code to add something like posts on side and above is time of adding it but only first post are getting updated time but next posts have time of first one (first are getting 16:35 and next have 16:35 also) here is code of data.php

session_start();
$dzien = date("d");
$mies = date ("m");
$rok = date("Y");
$_SESSION['data'] = $dzien.".".$mies.".".$rok;
$godz = date("G");
$min = date("i");
$_SESSION['czas'] = $godz.":".$min; 
header("Location: edit.php");
exit();

And here is file.php which add posts and time:

session_start();
header("Location: data.php");
$tekst ="<div class='wpis'><div class='data' ><p class='tdata'>".$_SESSION['data']." ".$_SESSION['czas']."</p></div><div class='klaska'>". $_POST['pole']."</div></div>";
$fp = fopen("inne.txt", "r");
$stare = fread($fp,filesize("inne.txt"));
fclose($fp);
$ntekst = $tekst.$stare;
$fp = fopen("inne.txt", "w");
fputs($fp,$ntekst);
fclose($fp);
header("Location: index.php");
exit();

I want to get in next posts updated time of add

Line 2 of file.php prepares a header to redirect to data.php, but at the end of the file you prepare another header to redirect to index.php. See comment by shutout2730 at yahoo dot com in link : Likely the first redirect is replaced by the later one and hence does nothing. There appear to be exceptions based on output echo, print and buffering. Are you running data.php from someplace else to initialise it? I suspect data.php is not called as you expect and hence session is not being updated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM