php - Session variable not working in real time -


i have user comment system in time of comment displayed using utc timestamp stored in database along comments.

the time offset used set session timeoffset variable using javascript post request user local time.

i have done because user diffrent timezone , cannot store time in 1 time zone alone have stored in utc , displayed using timeoffset of timezone.

this system not working in real time working after refresh.

comments.php

<?php  session_save_path('session/store'); session_start(); ?>  <script type="text/javascript" src="jquery/jquery.js"></script> <script type="text/javascript"> var timeoffset = new date().gettimezoneoffset();  $.post('timeoffset.php', {timeoffset:timeoffset}, function(data){     //alert(data); }); </script>  <?php if(isset($_session['timeoffset'])&&!empty($_session['timeoffset'])){     date_default_timezone_set('utc');     $timeoffset = (int)$_session['timeoffset']; } else{     echo 'timeoffset not set';     exit; }   // here comments displayed using while loop  // time of comments displayed  echo gmdate("f j, y, h:i:s a", $row['timestamp']-($timeoffset*60)); //$row['timestamp'] = utc time stamp stored in database. e.g: 1377509788 ?> 

timeoffset.php

<?php session_save_path('session/store'); session_start();  if(isset($_post['timeoffset'])){     $_session['timeoffset'] = (int)$_post['timeoffset'];     echo $_session['timeoffset']; } ?> 

it shows timeoffset not set first , after refresh shows comments , time.

please see , suggest possible way this.

thanks.

the php code executed before user gets page displayed. because of that, doesn't matter if code in document before or after javascript code executed in client's browser. have add time via javascript , ajax, too. alet in post request should give right result.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -