By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,294 Members | 2,645 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,294 IT Pros & Developers. It's quick & easy.

Help with time-date in php-file

P: n/a
Help needed with this: I have had a guestbook-page in Europe and will
now have to move it to a US based-server. This makes the
time-function showing time 6 hours wrong. The time should be GMT minus
6 hours. Can anyone help me with that? Her's the code:

<?php
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

?>
<p><pre>

</pre>
<body bgcolor="beige" text=darkred leftmargin=20>
<center><h2>Chat</H2></CENTER>

<form method="post" action="lagra.php3">

<span class="text"> Message:</SPAN><br><TEXTAREA name=meddel rows=5
cols=50></TEXTAREA><br>
<span class="text"> Name:</SPAN><br>
<input name="namn" ></INPUT><br>

<input type="submit" name="submit" value="Skicka"></INPUT>
</FORM><?
// ------ Editera dessa! --------------
$persida=10; // Antal inlägg som skall visas per sida.
$noprev="noprev.gif"; // Sökväk till deaktiverad föregångar-knapp.
$nonext="nonext.gif"; // Sökväg till deaktiverad nästa-knapp.
$prev="prev.gif"; // Sökväg till föregångar-knapp.
$next="next.gif"; // Sökväg till nästa-knapp.
// ------------------------------------

$sidor=0;
$storlek=0;
$namn="";
$epost="";
$meddelande="";
$titel="";
$hemsida="";
$sidnr=1;

$ipnr="";
$tidp="";
$datum="";

function initiera(){
// Initiering av de komponenter som behövs. Körs alltid först!

global $sidor, $persida, $namn, $epost, $meddelande, $hemsida, $titel,
$storlek, $start, $sidnr, $ipnr, $tidp, $datum;
// Läs i fil antalet inlägg i gästboken
if(!($fpread = fopen("inlagg.txt", 'r'))){
$fpwrite = fopen("inlagg.txt", 'w');
fputs($fpwrite,"0\n");
fclose($fpwrite);
$sidor=1;
$storlek=0;
}else{
$storlek=fgets($fpread,4096);
$sidnr=floor($start/$persida)+1;
// Beräkna hur många sidor dessa inlägg tar
$sidor=ceil($storlek/$persida);
if($sidor==0) $sidor=1;
// Läser igenom dagboksfil en och lagrar inlägg som skall visas på
denna sida
$mess=0;
$index=0;
while(!feof($fpread)){
$data1=fgets($fpread,200);
$data2=fgets($fpread,200);
$data3=fgets($fpread,200);
$data4=fgets($fpread,200);
$data5=fgets($fpread,2020);
$data6=fgets($fpread,4096);
$tom=fgets($fpread,4096);
if($mess>= $start &amp;&amp;$mess&lt;$start+$persida){
$namn[$index]=$data1;
$epost[$index]=$data2;
$hemsida[$index]=$data3;
$titel[$index]=$data4;
$meddelande[$index]=$data5;
list($ipnr[$index],$datum[$index],$a,$b,$c)=explode(":",$data6);
$tidp[$index]="$a:$b";

$index=$index+1;
}
$mess++;
}
}
}
function visa_nav(){
global $start,$persida,$storlek,$sidor,$sidnr;

echo "::: ";
for($i=1;$i&lt;=$sidor;$i++)
if($i==$sidnr)
echo "<A href='\"$PHP_SELF?start=".($i-1)*$persida."\"' \??
$PHP_SELF?start=".($i-1)*$persida."><b>$i</B></A>::: ";
else
echo "<A href='\"$PHP_SELF?start=".($i-1)*$persida."\"' \??
$PHP_SELF?start=".($i-1)*$persida.">$i</A> :::
";
} function
visa_nav_framat(){ // Visar navigeringsknapp för
"nästa" global $start, $sidor, $persida,
$storlek; global $next,
$nonext;if($start+$persida&lt;$storlek){
$newpage=$start+$persida;
echo "<A href='\"$PHP_SELF?start=$newpage\"'
$PHP_SELF?start='$newpage\""'><IMG src='\"".$next."\"' border='\"0\"'
?.$next.?\??></A>";
}else{
echo "<IMG src='\"".$nonext."\"' ?.$nonext.?\??>";
}
}
function visa_nav_bakat(){
// Visar navigeringsknapp för "föregående"
global $start, $sidor, $persida, $storlek;
global $prev, $noprev;

if($start&gt;=$persida){
$newpage=$start-$persida;
echo "<A href='\"$PHP_SELF?start=$newpage\"'
$PHP_SELF?start='$newpage\""'><IMG src='\"".$prev."\"' border='\"0\"'
?.$prev.?\??></A>";
}else{
echo "<IMG src='\"".$noprev."\"' ?.$noprev.?\??>";
}
}
function visa_antal_meddelanden(){
global $storlek;
echo $storlek;
}
function visa_antal_sidor(){
global $sidor;
echo $sidor;
}
function visa_sidnr(){
global $sidnr;
echo $sidnr;
}
function visa_meddelande($index){
global $namn, $epost, $meddelande, $hemsida, $titel, $start, $storlek,
$persida, $sidor, $ipnr, $tidp, $datum;
$sidan=floor($start/$persida)+1;
$limit=$persida;
if(($sidan== $sidor) &amp;&amp;($storlek
%$persida)&gt;0)
$limit=$storlek%$persida; if($index&lt;$limit
&amp;&amp;$storlek&gt;0){
//////////////////////////////////////////////////////////////

echo "

Datum: <i>$datum[$index]</I> Klockan <i>$tidp[$index]</I><br>

Namn: <b>$namn[$index]</B></FONT><br>

<font color='black'>$meddelande[$index]</FONT><br><br><hr>
"; /////////////////////////////////////////////////////////////// } }
?&gt; <! ----------------------------------------------- !><! Utför
initiera först !><?initiera();?>
<CENTER><BR><?visa_nav();?><BR>Det finns
<?visa_antal_meddelanden();?>meddelanden på
<?visa_antal_sidor();?>sidor. Detta
är sida <?visa_sidnr();?>. </CENTER><BR>
<HR>
<! Visa alla inläggen på sidan !><?
for($i=0;$i<=$persida;$i++)
visa_meddelande($i);
?><TR><TD></BODY></HTML>

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Gerry wrote:
Help needed with this: I have had a guestbook-page in Europe and will
now have to move it to a US based-server. This makes the
time-function showing time 6 hours wrong. The time should be GMT minus
6 hours. Can anyone help me with that? Her's the code:

[snip]

You might want to narrow the post down to the particular code that deals
with times.

If you're using the mktime() or date() function somewhere to format
times, note that you can generally control the timezone by setting the
TZ environment variable with putenv(). Also note gmmktime() and gmdate()
which work with GMT only.

-- brion vibber (brion @ pobox.com)
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.