TIME DIFFERENCE ERROR

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tzinyii
Forum Newbie
Posts: 5
Joined: Sun Jan 14, 2007 3:14 am

TIME DIFFERENCE ERROR

Post by tzinyii »

I would like to use a PHP guestbook created by someone for free downloading. I like it because it allows one to redesign in accordance to one's liking and also set the time difference accordingly.

But i have a problem here. The server from USA that I use has a time difference of 5 hours from the guestbook setting that I use.
I modify the time difference setting but the time during which any message posted between 12.01am to 4.59am becomes 24.01 - 28.59 .

I have consulted the person who created the guestbook but he could not help:(
I would be very grateful if someone could help.

Appended below are excerpts of the codes used for setting the time difference:

Code: Select all

<? require("check.php") ;?>
<?
if($_POST['ghtml'] != "")
{
$gname=str_replace("&#8741;","", $_POST['gname']);
$gup=str_replace("&#8741;","", $_POST['gup']);
$guser=str_replace("&#8741;","", $_POST['guser']);
$gmail=str_replace("&#8741;","", $_POST['gmail']);
$ghome=str_replace("&#8741;","", $_POST['ghome']);
$gwidth=str_replace("&#8741;","", $_POST['gwidth']);
$gn=str_replace("&#8741;","", $_POST['gn']);
$gnnumber=str_replace("&#8741;","", $_POST['gnnumber']);
$ghtml=str_replace("&#8741;","", $_POST['ghtml']);
$gup=str_replace("&#8741;","", $_POST['gup']);
$gm_link=str_replace("&#8741;","", $_POST['gm_link']);
$gu_link=str_replace("&#8741;","", $_POST['gu_link']);
$go_link=str_replace("&#8741;","", $_POST['go_link']);
$gc_link=str_replace("&#8741;","", $_POST['gc_link']);
$gm_line=str_replace("&#8741;","", $_POST['gm_line']);
$gi_line=str_replace("&#8741;","", $_POST['gi_line']);
$go_skin=str_replace("&#8741;","", $_POST['go_skin']);
$gm_skin=str_replace("&#8741;","", $_POST['gm_skin']);
$gc_skin=str_replace("&#8741;","", $_POST['gc_skin']);
$gf_type=str_replace("&#8741;","", $_POST['gf_type']);
$gip=str_replace("&#8741;","", $_POST['gip']);
$gt_y=str_replace("&#8741;","", $_POST['gt_y']);
$gt_m=str_replace("&#8741;","", $_POST['gt_m']);
$gt_d=str_replace("&#8741;","", $_POST['gt_d']);
$gt_h=str_replace("&#8741;","", $_POST['gt_h']);
$gt_s=str_replace("&#8741;","", $_POST['gt_s']);
$g_boy=str_replace("&#8741;","", $_POST['g_boy']);
$g_girl=str_replace("&#8741;","", $_POST['g_girl']);
$system=$gname."&#8741;".$gup."&#8741;".$guser."&#8741;".$gmail."&#8741;".$ghome."&#8741;".$gwidth. "&#8741;".$gnnumber."&#8741;".$gn."&#8741;".$gm_link."&#8741;".$gu_link."&#8741;".$go_link."&#8741;".$gc_link. "&#8741;".$gm_line."&#8741;".$gi_line."&#8741;".$go_skin."&#8741;".$gm_skin."&#8741;".$gc_skin."&#8741;".$gf_type. "&#8741;".$gip."&#8741;".$gt_y."&#8741;".$gt_m."&#8741;".$gt_d."&#8741;".$gt_h."&#8741;".$gt_s."&#8741;".$g_boy."&#8741;".$g_girl."&#8741;".$ghtml;
$f=fopen("gtype.dat","w+");
fputs($f,$system);
fclose($f);
echo "<table border=0 width=150><tr><td><fieldset><center><br>". "<font color=Red size=2><legend>finish editing</legend></font><a href=javascript:history.back(1)>". "<font color=$gm_link size=2>return to previous page</font></a><hr color=$gu_link width=150 size=1>". "</fieldset></td></tr></table>";
}
?>

Code: Select all

<form action="gsave.php?cookie=yes" method="post">
<tr>
<td width="55%" style="border: 1 solid #C0C0C0"><font size="2">time difference </font></td>
<td width="47%" style="border: 1 solid #C0C0C0"><font size="2">year&#65306;<input type="text" name="gt_y" size="2" value="<?=$gt_y;?>">month&#65306;<input type="text" name="gt_m" size="2" value="<?=$gt_m;?>">date&#65306;<input type="text" name="gt_d" size="2" value="<?=$gt_d;?>">hour&#65306;<input type="text" name="gt_h" size="2" value="<?=$gt_h;?>">minute&#65306;<input type="text" name="gt_s" size="2" value="<?=$gt_s;?>"></font></td>
</tr>
Last edited by tzinyii on Sun Jan 14, 2007 8:29 pm, edited 2 times in total.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Firstly I'll ask you politely not to use all uppercase characters in your thread subjects.
Secondly: We should probably help you improve this code a bit from a duplication, readability standpoint so that it is easier to debug but trying to solve the bug itself.

So, do you know what all these are for?

Code: Select all

$gname, $gup, $guser, $gmail, $ghome, $gwidth, $gn, $gnnumber, $ghtml, $gup, $gm_link, $gu_link, $go_link, $gc_link, $gm_line, $gi_line, $go_skin, $gm_skin, $gc_skin, $gf_type, $gip, $gt_y, $gt_m, $gt_d, $gt_h, $gt_s, $g_boy, $g_girl
Could you perhaps give them better names or organise them into associative arrays?
tzinyii
Forum Newbie
Posts: 5
Joined: Sun Jan 14, 2007 3:14 am

Post by tzinyii »

Oops, sorry about the uppercase characters in the thread subjects.
I am very new to php and could not interpret the code written by the author of the guestbook.

Below is the link to the guestbook:
http://melody.freeprohost.com/guest.php

I would appreciate if someone could help.

I found this code for fixing time difference for PHP script where the number "15" is the hour difference of 15.
I wonder if this code is relevant for fixing the error that I encounter and if so, where should I insert the code ?

$currentDateTime = date("Y-m-d H:i:s", mktime(date("H") + 15, date("i"), date("s"), date("m"), date("d"), date("Y")));
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Code: Select all

$currentDateTime = date("Y-m-d H:i:s", mktime(date("H") + 15, date("i"), date("s"), date("m"), date("d"), date("Y")));
Not quite. If you have php 5 you can use this. If you don't this should work:

Code: Select all

date("Y-m-d H:i:s", mktime() + 60 * 60 * 15);
tzinyii
Forum Newbie
Posts: 5
Joined: Sun Jan 14, 2007 3:14 am

Post by tzinyii »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Many thanks for your prompt reply, ole.
Could someone shed some light on I should the above code? 

In the gsave.php, there is the following code. I wonder if this is where I should insert and if so, how:

Code: Select all

<?
$gname=str_replace("&#8741;","", $HTTP_POST_VARS['gname']);
$gup=str_replace("&#8741;","", $HTTP_POST_VARS['gup']);
$guser=str_replace("&#8741;","", $HTTP_POST_VARS['guser']);
$gmail=str_replace("&#8741;","", $HTTP_POST_VARS['gmail']);
$ghome=str_replace("&#8741;","", $HTTP_POST_VARS['ghome']);
$gwidth=str_replace("&#8741;","", $HTTP_POST_VARS['gwidth']);
$gn=str_replace("&#8741;","", $HTTP_POST_VARS['gn']);
$gnnumber=str_replace("&#8741;","", $HTTP_POST_VARS['gnnumber']);
$ghtml=str_replace("&#8741;","", $HTTP_POST_VARS['ghtml']);
$gup=str_replace("&#8741;","", $HTTP_POST_VARS['gup']);
$gm_link=str_replace("&#8741;","", $HTTP_POST_VARS['gm_link']);
$gu_link=str_replace("&#8741;","", $HTTP_POST_VARS['gu_link']);
$go_link=str_replace("&#8741;","", $HTTP_POST_VARS['go_link']);
$gc_link=str_replace("&#8741;","", $HTTP_POST_VARS['gc_link']);
$gm_line=str_replace("&#8741;","", $HTTP_POST_VARS['gm_line']);
$gi_line=str_replace("&#8741;","", $HTTP_POST_VARS['gi_line']);
$go_skin=str_replace("&#8741;","", $HTTP_POST_VARS['go_skin']);
$gm_skin=str_replace("&#8741;","", $HTTP_POST_VARS['gm_skin']);
$gc_skin=str_replace("&#8741;","", $HTTP_POST_VARS['gc_skin']);
$gf_type=str_replace("&#8741;","", $HTTP_POST_VARS['gf_type']);
$gip=str_replace("&#8741;","", $HTTP_POST_VARS['gip']);
[color=red]$gt_y=str_replace("&#8741;","", $HTTP_POST_VARS['gt_y']);
$gt_m=str_replace("&#8741;","", $HTTP_POST_VARS['gt_m']);
$gt_d=str_replace("&#8741;","", $HTTP_POST_VARS['gt_d']);
$gt_h=str_replace("&#8741;","", $HTTP_POST_VARS['gt_h']);
$gt_s=str_replace("&#8741;","", $HTTP_POST_VARS['gt_s']);[/color]$g_boy=str_replace("&#8741;","", $HTTP_POST_VARS['g_boy']);
$g_girl=str_replace("&#8741;","", $HTTP_POST_VARS['g_girl']);
$system=$gname."&#8741;".$gup."&#8741;".$guser."&#8741;".$gmail."&#8741;".$ghome."&#8741;".$gwidth."&#8741;".$gnnumber. "&#8741;".$gn."&#8741;".$gm_link."&#8741;".$gu_link."&#8741;".$go_link."&#8741;".$gc_link."&#8741;".$gm_line."&#8741;".$gi_line."&#8741;".$go_skin. "&#8741;".$gm_skin."&#8741;".$gc_skin."&#8741;".$gf_type."&#8741;".$gip."&#8741;".$gt_y."&#8741;".$gt_m."&#8741;".$gt_d."&#8741;".$gt_h."&#8741;".$gt_s."&#8741;".$g_boy."&#8741;".$g_girl."&#8741;".$ghtml;
$f=fopen("gsystem.dat","w+");
fputs($f,$system);
fclose($f);

echo "<table border=0 width=150><tr><td><fieldset><center><br><font color=Red size=2><legend>finished editing</legend></font><a href=javascript:history.back(1)><font color=$gm_link size=2>back to the previous page</font></a><hr color=$gu_link width=150 size=1><a href=guest.php?cookie_clear=yes><font color=$gm_link size=2>back to main page</font></a></fieldset></td></tr></table>";
?>
</body>
</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
tzinyii
Forum Newbie
Posts: 5
Joined: Sun Jan 14, 2007 3:14 am

Post by tzinyii »

The files for the setting up of the guestbook could be downloaded from

http://s94.tku.edu.tw/

I would very much appreciate if someone could help.
Last edited by tzinyii on Mon Feb 26, 2007 8:28 am, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

in result.php and re.php replace
$y=date("Y")+$gt_y;
$m=date("n")+$gt_m;
$d=date("d")+$gt_d;
$h=date("G")+$gt_h;
$i=date("i")+$gt_s;
$s=date("s");
by

Code: Select all

$date = getdate();
$t = date('Y/n/d  G:i:s', mktime($date['hours']+$gt_h, $date['minutes']+$gt_s, $date['seconds'], $date['mon']+$gt_m, $date['mday']+$gt_d, $date['year']+$gt_y));
and remove the line
$t="".$y."/".$m."/".$d." ".$h.":".$i.":".$s."";
tzinyii
Forum Newbie
Posts: 5
Joined: Sun Jan 14, 2007 3:14 am

Post by tzinyii »

The problem that has been haunting me since day one has now finally been resolved.
I have consulted many people in many forums before but to no avail.
Words cannot express how much I appreciate your kind assistance, Volka.
Thanks a million to you. May you be blessed with all beautiful things in life.
Post Reply