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

Still badly need help, time-date

P: n/a
As I'm not a PHP-prgrammer at all, I just need Help 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+
4 Replies


P: n/a
Gerry wrote:
As I'm not a PHP-prgrammer at all, I just need Help 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]

Mind if I make a suggestion?
Make a *short* script that shows your problem and post that.

Example:
When I run the script below I get

2004-10-25 21:45:12 GMT

but I'd like to get

2004-10-25 16:45:12 CDT

=======================================

<?php
$now = time();
echo date('Y-m-d H:i:s T', $now), "\n";
?>

--
USENET would be a better place if everybody read: | to mail me: simply |
http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
http://www.expita.com/nomime.html | and *NO* attachments. |
Jul 17 '05 #2

P: n/a
On 25 Oct 2004 22:17:04 GMT, Pedro Graca <he****@hotpop.com> wrote:
Gerry wrote:
As I'm not a PHP-prgrammer at all, I just need Help 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]

Mind if I make a suggestion?
Make a *short* script that shows your problem and post that.

Example:
When I run the script below I get

2004-10-25 21:45:12 GMT

but I'd like to get

2004-10-25 16:45:12 CDT

=======================================

<?php
$now = time();
echo date('Y-m-d H:i:s T', $now), "\n";
?>

From this script I get GMT +1, I want + 6 hours which is the US-time
at the servers location. I want the server to give gmt +1 though
situated in US:

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>
Jul 17 '05 #3

P: n/a
Gerry wrote:
On 25 Oct 2004 22:17:04 GMT, Pedro Graca <he****@hotpop.com> wrote:
Gerry wrote:
As I'm not a PHP-prgrammer at all, I just need Help 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]

Mind if I make a suggestion?
Make a *short* script that shows your problem and post that.

Example:
When I run the script below I get

2004-10-25 21:45:12 GMT

but I'd like to get

2004-10-25 16:45:12 CDT

=======================================

<?php
$now = time();
echo date('Y-m-d H:i:s T', $now), "\n";

From this script I get GMT +1, I want + 6 hours which is the US-time
at the servers location. I want the server to give gmt +1 though
situated in US:

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>


Another visible reason to always use english varnames and proper
indentation, I can't make anything out of this, sorry.
Jul 17 '05 #4

P: n/a
Gerry wrote:
<?php
$now = time();
echo date('Y-m-d H:i:s T', $now), "\n";
?>


From this script I get GMT +1, I want + 6 hours which is the US-time
at the servers location. I want the server to give gmt +1 though
situated in US:

try these!

$bst = date('D, d m Y H:i:s',strtotime("now BST"));
$est = date('D, d m Y H:i:s',strtotime("now EST"));
$cst = date('D, d m Y H:i:s',strtotime("now CST"));
$gmt = date('D, d m Y H:i:s',strtotime("now GMT"));

print "BST = $bst <br>";
print "GMT = $gmt <br>";
print "EST = $est <br>";
print "CST = $cst <br>";

and swap the obvious bit with the neccessary timezone identifier.

Hopefully the server in the US will have its clock set to GMT and local
time provided by reference to the correct timezone.
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.