11 Replies - 1817 Views - Last Post: 07 October 2011 - 06:18 PM Rate Topic: -----

#1 swim_fan08  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 19-February 09

Guestbook Time

Posted 05 October 2011 - 05:35 PM

Is there a way that when my user signs my guestbook, the time shows up in there timezone? For example, I live in the central timezone and if I post an entry in my guestbook at 6:00PM and someone who lives in the east coast reads my guestbook entry and its 7:00PM. Right now, I just have it set up to show me the time in EST.

Also, how can I put my entries in descending order and is there a way that I can generate an email to me notifying me that there is a a new entry in my guestbook?


<HTML>
<HEAD>
<style type="text/css">
<!--
.style1 {font-size: 12px}
body,td,th {
	font-size: 14px;
}
a {
	font-size: 12px;
}
body {
	background-color: #CCCCCC;
	SCROLLBAR-FACE-COLOR: #0066FF; MARGIN: 0px; SCROLLBAR-HIGHLIGHT-COLOR: #0066FF; SCROLLBAR-SHADOW-COLOR: #0066FF; SCROLLBAR-3DLIGHT-COLOR: #0066FF; SCROLLBAR-ARROW-COLOR: #51B0F2; SCROLLBAR-TRACK-COLOR: #51B0F2; Courier New; SCROLLBAR-DARKSHADOW-COLOR: #000000
}
a:link {
	color: #0066FF;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #0066FF;
}
a:hover {
	text-decoration: underline;
	color: #0066FF;
}
a:active {
	text-decoration: none;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><BODY>
<form method="post" action="addguestbook.php">
<div align="center"></div>
<div align="center"></div>
<div align="center" class="style1"></div>
<div align="center"><span class="style1">Name:</span><br />
  <input name="name" type="text" size="30" maxlength="40" />
  <br />
  <span class="style1"><br />
  Email:</span><br />
<input name="email" type="text" size="30" maxlength="40" />
<br />
<br />
<span class="style1">Home Page:</span><br />
<input name="site" type="text" size="30" value="http://" maxlength="40" />
<br />
<br />
<span class="style1">Message:</span><br />
<textarea name="msg" cols="22" rows="6"></textarea>
<br />
<br />
<input type="reset" value="Reset" />
&nbsp;
<input type="submit" value="Send" />
</div>
<div align="center">
  <p>&nbsp;</p>
<?php
$file = "guestbook.txt";
 
if (fopen($file, "r")) {
$fil = "guestbook.txt";
$fo = fopen ($fil, "r");
$con = fread ($fo,filesize ($fil));
fclose ($fo);
echo "$con";
} else {
echo "<h3>Sorry there was an error please contact us now<h3>";
}
?></div>
</BODY>
</HTML>





 
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body,td,th {
	font-size: 12px;
	color: #000000;
}
a:link {
	text-decoration: none;
	color: #0066FF;
}
a:visited {
	text-decoration: none;
	color: #0066FF;
}
a:hover {
	text-decoration: underline;
	color: #0066FF;
}
a:active {
	text-decoration: none;
}
body {
	background-color: #CCCCCC;
	SCROLLBAR-FACE-COLOR: #0066FF; MARGIN: 0px; SCROLLBAR-HIGHLIGHT-COLOR: #0066FF; SCROLLBAR-SHADOW-COLOR: #0066FF; SCROLLBAR-3DLIGHT-COLOR: #0066FF; SCROLLBAR-ARROW-COLOR: #51B0F2; SCROLLBAR-TRACK-COLOR: #51B0F2; Courier New; SCROLLBAR-DARKSHADOW-COLOR: #000000
}
-->
</style>
</HEAD>
<BODY>

<?php

date_default_timezone_set('America/New_York');
date('h:i:s a');




$file           = "guestbook.txt";
$name		= $_POST['name'];
$email		= $_POST['email'];
$site   	= $_POST['site'];
$msg		= $_POST['msg'];

$site   = stripslashes($site);
$msg  = stripslashes($msg);
$email  = stripslashes($email);
$name = stripslashes($name);

$msg = nl2br(htmlentities($msg));
$site = nl2br(htmlentities($site));
$email = nl2br(htmlentities($email));
$name = nl2br(htmlentities($name));
 
if(empty($email) || empty($name) || empty($msg)) {
	echo "<h3>Sorry all fields are required</h3>";
} else {
 
$fp = fopen($file,"a");
 
$timestamp=date("M-d-Y h:m:s A");
fwrite($fp, '
<font size="3">
<BR><BR>
Posted: '.$timestamp.'<br />
Name: '.$name.'<BR>
Email: <a href="mailto:'.$email.'">'.$email.'</a><BR>
Home Page: <a href="'.$site.'">'.$site.'</a><BR>Message: '.$msg.'<BR>
');
 
fclose($fp);
 
echo '<font size="3"><p align="center">Thank you '.$name.' for singing my guestbook</p></font>'; 
}
?>
<div align="center"></div>
<div align="center"></div>
<div align="center"></div>
<div align="center"></div>
<p align="center"><a href="YOU`R INDEX.PHP LINK HERE">Back to GuestBook</a></p>
<div align="center"></div>
</BODY>
</HTML>
 

 





Is This A Good Question/Topic? 0
  • +

Replies To: Guestbook Time

#2 swim_fan08  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 19-February 09

Re: Guestbook Time

Posted 05 October 2011 - 05:42 PM

I think I may have figured out to do notifications. I am not too sure if this right.



           if (!$file) {  
                $name=$_POST['name'];
		$email=$_POST['email'];
		$subject = 'New Guestbook Entry'; 
		$msg=$_POST['msg'];

		mail("myemailaddress@gmail.com","$subject",
		$message,"From: $name <$email>"); 



Was This Post Helpful? 0
  • +
  • -

#3 LiDoNg_9_0  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 159
  • Joined: 03-September 09

Re: Guestbook Time

Posted 05 October 2011 - 05:50 PM

I think there's no way to get the client's timezone using pure php. If It has, will Im sure I dont know about that..Will the best way to do that is getting a Cookie through Javascript that will hold the client's timezone. You could also send the timezone via Ajax to the server and have it do whatever you need to do it with then. Or, if you are not doing any serverside calculations with it, just apply the timezone client side where needed. In addition to that, I suggest you let the visitor set his timezone himself and store that in the Cookie or a Session.

Have a look at THIS site.. Hope it helps
Was This Post Helpful? 1
  • +
  • -

#4 codematrix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-September 11

Re: Guestbook Time

Posted 05 October 2011 - 05:58 PM

I agree with getting a Cookie through Javascript that will hold the client's timezone. I thinks its better..
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2992
  • Posts: 10,337
  • Joined: 08-August 08

Re: Guestbook Time

Posted 05 October 2011 - 06:16 PM

Javascript to get the UT, which needs to be converted to GMT for PHP to use:
<script language="javascript">
function GetClientUTC() {
	var now = new Date();
	alert(now.getTimezoneOffset());
}

GetClientUTC();
</script>

You still need to do the Ajax or cookie. ;)
Was This Post Helpful? 0
  • +
  • -

#6 swim_fan08  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 19-February 09

Re: Guestbook Time

Posted 06 October 2011 - 05:31 PM

Just making sure that I making sure that I am understanding things correct.


<HTML>

var now = new Date();
var later = new Date();
// Set time for how long the cookie should be saved
later.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
// Set cookie for the time zone offset in minutes
setCookie(“time_zone_offset”, now.getTimezoneOffset(), later, “/”);
// Create two new dates
var d1 = new Date();
var d2 = new Date();
// Date one is set to January 1st of this year
// Guaranteed not to be in DST for northern hemisphere,
// and guaranteed to be in DST for southern hemisphere
// (If DST exists on client PC)
d1.setDate(1);
d1.setMonth(1);
// Date two is set to July 1st of this year
// Guaranteed to be in DST for northern hemisphere,
// and guaranteed not to be in DST for southern hemisphere
// (If DST exists on client PC)
d2.setDate(1);
d2.setMonth(7);
// If time zone offsets match, no DST exists for this time zone
if(parseInt(d1.getTimezoneOffset())==parseInt(d2.getTimezoneOffset()))
{
setCookie(“time_zone_dst”, “0″, later, “/”);
}
// DST exists for this time zone – check if it is currently active
else {
// Find out if we are on northern or southern hemisphere
// Hemisphere is positive for northern, and negative for southern
var hemisphere = parseInt(d1.getTimezoneOffset())-parseInt(d2.getTimezoneOffset());
// Current date is still before or after DST, not containing DST
if((hemisphere>0 && parseInt(d1.getTimezoneOffset())==parseInt(now.getTimezoneOffset())) ||
(hemisphere<0 && parseInt(d2.getTimezoneOffset())==parseInt(now.getTimezoneOffset()))) { setCookie(“time_zone_dst”, “0″, later, “/”); } // DST is active right now with the current date else { setCookie(“time_zone_dst”, “1″, later, “/”); } }
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body,td,th {
	font-size: 12px;
	color: #000000;
}
a:link {
	text-decoration: none;
	color: #0066FF;
}
a:visited {
	text-decoration: none;
	color: #0066FF;
}
a:hover {
	text-decoration: underline;
	color: #0066FF;
}
a:active {
	text-decoration: none;
}
body {
	background-color: #CCCCCC;
	SCROLLBAR-FACE-COLOR: #0066FF; MARGIN: 0px; SCROLLBAR-HIGHLIGHT-COLOR: #0066FF; SCROLLBAR-SHADOW-COLOR: #0066FF; SCROLLBAR-3DLIGHT-COLOR: #0066FF; SCROLLBAR-ARROW-COLOR: #51B0F2; SCROLLBAR-TRACK-COLOR: #51B0F2; Courier New; SCROLLBAR-DARKSHADOW-COLOR: #000000
}
-->
</style>
<script language="javascript">
function GetClientUTC() {
	var now = new Date();
	alert(now.getTimezoneOffset());
}

GetClientUTC();
</script>
</HEAD>
<BODY>

<?php



date_default_timezone_set('America/New_York');
date('h:i:s a');

$time_zone_name = timezone_name_from_abbr(”, -$_COOKIE['time_zone_offset']*60, $_COOKIE['time_zone_dst']);




$file           = "guestbook.txt";
$name		= $_POST['name'];
$email		= $_POST['email'];
$site   	= $_POST['site'];
$msg		= $_POST['msg'];

$site   = stripslashes($site);
$msg  = stripslashes($msg);
$email  = stripslashes($email);
$name = stripslashes($name);

$msg = nl2br(htmlentities($msg));
$site = nl2br(htmlentities($site));
$email = nl2br(htmlentities($email));
$name = nl2br(htmlentities($name));
 
if(empty($email) || empty($name) || empty($msg)) {
	echo "<h3>Sorry all fields are required</h3>";
} else {
 
$fp = fopen($file,"a");
 
$timestamp=date("M-d-Y h:m:s A");
fwrite($fp, '
<font size="3">
<BR><BR>
Posted: '.$timestamp.'<br />
Name: '.$name.'<BR>
Email: <a href="mailto:'.$email.'">'.$email.'</a><BR>
Home Page: <a href="'.$site.'">'.$site.'</a><BR>Message: '.$msg.'<BR>
');
 
fclose($fp);
 
echo '<font size="3"><p align="center">Thank you '.$name.' for singing my guestbook</p></font>'; 
}
?>
<div align="center"></div>
<div align="center"></div>
<div align="center"></div>
<div align="center"></div>
<p align="center"><a href="YOU`R INDEX.PHP LINK HERE">Back to GuestBook</a></p>
<div align="center"></div>
</BODY>
</HTML>
 




Was This Post Helpful? 0
  • +
  • -

#7 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2992
  • Posts: 10,337
  • Joined: 08-August 08

Re: Guestbook Time

Posted 06 October 2011 - 05:57 PM

I would not put Javascript, HTML, PHP, and CSS in one file,
Was This Post Helpful? 0
  • +
  • -

#8 swim_fan08  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 19-February 09

Re: Guestbook Time

Posted 06 October 2011 - 06:35 PM

Can I have a little help getting started? I've always had all my code in one file and never really had any of my code in separate files.
Was This Post Helpful? 0
  • +
  • -

#9 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2992
  • Posts: 10,337
  • Joined: 08-August 08

Re: Guestbook Time

Posted 06 October 2011 - 09:06 PM

It's not that it can't work in one file. The problem is that it's so much harder to manage.
http://www.dreaminco...ode-separation/
There's a reason we have .php, .html, .js and .css files: better organization.
Was This Post Helpful? 0
  • +
  • -

#10 swim_fan08  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 19-February 09

Re: Guestbook Time

Posted 07 October 2011 - 05:40 PM

It makes more sense. :yes: Do I need any special software to make .js files also?
Was This Post Helpful? 0
  • +
  • -

#11 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2992
  • Posts: 10,337
  • Joined: 08-August 08

Re: Guestbook Time

Posted 07 October 2011 - 05:55 PM

They're all just text files. It's how they're used that matters.
Was This Post Helpful? 0
  • +
  • -

#12 swim_fan08  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 19-February 09

Re: Guestbook Time

Posted 07 October 2011 - 06:18 PM

Ok, got it! Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1