Page 1 of 1

Date warning php 5 using date_default_timezone_set

Posted: Thu Sep 18, 2014 7:13 pm
by darknkreepy3#
When older tutorials allow you to use Date to get date and time for your script in php, now it is better and almost forced to use a new way to lock down where the script is running to have server side date and time fixed properly.

so when you do this for a sendmail etc...

Code: Select all

$bodycopy=date("F j, Y, g:i a")."\n";
put this first so it gives [date] a bit more data

Code: Select all

date_default_timezone_set("America/New_York");
Together it would look like this:

sendmail.php (from a form that's action is sendmail.php)

Code: Select all

<?php
	/*
	11-03-2010. ©2010 by Kristoffe Brodeur. All Rights Reserved.
	09-18-2014

	test-sendmail-html.php v1.0 version works with

		html
		verizon fios dynamic ip
		sendmail.exe
		windows 7
		apache 2.2.1.7
		php 5.2.6

		fName
		fEmail
		fSubject
		fMessage
		
		date_default_timezone_set("America/New_York");
	*/
	$to_root="../../";
	//simple loop to recode post into usable vars
	foreach($_POST as $key=>$val)
		{
		${$key}=$val;
		}
	//new security for php, not just date
	date_default_timezone_set("America/New_York");
	$bodycopy=	date("F j, Y, g:i a")."\n";
	
	$bodycopy.=	"<p>$fMessage</p>";

	// In case any of our lines are larger than 70 characters, we should use wordwrap()
	$bodycopy=	wordwrap($bodycopy,40);
	$site=		"www.supercala.net";
	$fromE=		$fEmail;
	$title=		"$site: Contact Message";
	$toE=		"kristoffe.brodeur@verizon.net";
	$message="
		<html>
			<body>
				<h3>CONTACT MESSAGE FROM</h3>
				<h4>$site</h4>
				<h4>$fName</h4>
				<h4>$fIP</h4>
				$bodycopy
				<hr />
			</body>
		</html>";	

	//html version(line2 of $headers);
	$headers =
		'From: '.$fromE."\r\n".
		'Content-type: text/html'."\r\n".
		'Reply-To: '.$fromE."\r\n".
		'X-Mailer: PHP/'.phpversion();

	// Send
	echo "status:".mail($toE,$title,$message,$headers);				
?>

<script>
	//location.href="<?php echo $to_root;?>mS/contact/thankyou.php";
</script>
and here is the form itself

Code: Select all

<?php
	//-----found at roshanbh.com.np
	function getRealIpAddr()
		{
		//check ip from share internet
		if(!empty($_SERVER['HTTP_CLIENT_IP']))
			{$ip=$_SERVER['HTTP_CLIENT_IP'];}
		//to check ip is pass from proxy	
		elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
			{$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];}
		else
			{$ip=$_SERVER['REMOTE_ADDR'];}
		return $ip;
		}
	$visitor_ip=getRealIpAddr();	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
		<link rel="shortcut icon" path="favicon.ico" href="favicon.ico" type="image/x-icon" />
		<link type="text/css" rel="stylesheet" href="page.css" />
		<link href='http://fonts.googleapis.com/css?family=Pathway+Gothic+One' rel='stylesheet' type='text/css'>
		<link type="text/css" rel="stylesheet" href="contact.css" />
	</head>

	<body>
		<div id="wrap">
			<div id="menu">top menu design for your site can be here</div>
			<div class="clearBoth"></div>
			<div id="contact_area">
				<div id="contact_left">
					
					<div id="debug">Error</div>
				
					<form name='contact' method='POST' action='sendmail.php'>
						<table>
							<tr><td class='tdL'>Name</td><td>		<input 		class='inputR'	id='fName'		name='fName'	size='50'></td></tr>
							<tr><td class='tdL'>Email</td><td>		<input 		class='inputR'	id='fEmail'		name='fEmail'	size='50'></td></tr>
							<tr><td class='tdL'>Subject</td><td>	<input 		class='inputR'	id='fSubject'	name='fSubject'	size='50'></td></tr>
							<tr><td class='tdL'>IP</td><td>			<input 		class='inputR'	id='fIP'		name='fIP'		size='24' readonly value="<?php echo $visitor_ip;?>"></td></tr>
							<tr><td class='tdL'>Message</td><td>	<textarea 	class='textR'	id='fMessage'	name='fMessage' rows='8' cols='30'></textarea></td></tr>
							<tr><td class='tdL'>Send a copy to yourself</td><td></td></tr>
							<tr><td class='tdL'></td><td><input type='button' onclick='checkFields();' value='SEND EMAIL'></td></tr>
						</table>
					</form>
				</div>
				
				<div id="contact_right">
				</div>
				
				<div class="clearBoth"></div>
				
			</div>

			<div class="clearBoth"></div>
		
			<div id="footer">put your footer stuff here</div>
			<div class="clearBoth"></div>
		
		</div>
		
	</body>

</html>

<script>
	//
	var fEmail=document.getElementById('fEmail');
	var debug=document.getElementById('debug');
	var fIP=document.getElementById('fIP');
	var fMessage=document.getElementById('fMessage');
	//
	function checkFields()
		{
		//
		if(fEmail.value!=""&&fIP.value!=""&fMessage.value!="")
			{
			debug.innerHTML="!"+fEmail.value+fIP.value+fMessage.value;
			sendmail();
			}
		else
			{
			alert("please fill in your message and email.");
			}
		}
	//
	function sendmail()
		{
		document.contact.submit();
		}		
</script>
and contact.css

Code: Select all

#contact_area
	{
	background-image:url('../../backart/content.gif');
	background-repeat:repeat-x repeat-y;
	}
#contact_left,#contact_right
	{
	float:left;padding:16px;
	}
#contact_left
	{
	width:650px;
	}
#contact_right
	{
	}
.inputR,.textR
	{
	width:250px;
	margin:4px 0px 4px 0px;
	padding:4px;
	}
.tdL
	{
	width:150px;
	vertical-align:top;
	}
	
.inputR,.textR,.tdL
	{
	border-radius:6px;
	}
and page.css

Code: Select all

body
	{
	background-color:#000000;
	background-image:url('../backgrounds/backart-index.jpg');
	background-repeat:no-repeat;
	background-position:top center;
	font-size:12px;
	font-family: 'Pathway Gothic One', sans-serif;
	color:#979069;
	text-align:center;
	padding:0px;margin:0px;
	}

img{padding:0px;}
	
#wrap
	{
	text-align:center;
	width:1200px;
	margin:0px auto 0px auto;
	text-align:left;
	}
	
#menu
	{
	width:1200px;
	}
	
#menu_top,#menu_bot
	{
	float:left;
	background-color:#665dd4;
	width:1200px;
	}
#menu_bot
	{
	margin:2px 0px 16px 0px;
	}
#menu_top
	{
	background-color:#660000;
	}

.topItemActive
	{
	background-color:#FF0000;
	}
	
.topItemActive,.topItem
	{
	float:left;
	font-family: 'Pathway Gothic One', sans-serif;
	font-size:28px;
	padding:8px;
	border:solid;
	border-width:0px 0px 0px 1px;
	border-color:#FFFF00;
	}
.topItemActive a,.topItem a
	{
	text-decoration:none;
	}
	
.topItem:hover
	{
	background-color:#bebaf3;
	}

.sideItem a,.sideItem.topItemActive,.topItemActive a,.topItem a:visited,.topItem a
	{
	color:#FFFFFF;
	}
	
.newest img,#leftCol img,#rightCol img
	{
	border:none;
	}

.sideItem
	{	
	border:solid;
	border-width:0px 0px 1px 0px;
	border-color:#aa3737;
	background-color:#772222;
	padding:16px;
	font-size:24px;
	font-family: 'Pathway Gothic One', sans-serif;
	}
	
.sideItem a
	{
	text-decoration:none;
	}
		
.sideItem:hover
	{
	background:#ff3737;
	}
	
.submenuB
	{
	float:left;
	width:280px;
	padding:10px;
	font-size:20px;
	color:#772222;
	border:solid;
	border-color:#DDDDDD;
	border-width:1px;
	}
.submenuB p
	{
	text-align:justify;
	font-size:16px;
	padding:8px;
	}
	
#leftCol
	{
	float:left;width:250px;text-align:left;padding:8px 0px 8px 8px;
	color:#772222;font-size:12px;line-height:22px;
	border:solid;border-width:0px 4px 0px 0px;border-color:#550000;
	background-color:#772222;
	}

#leftCol p
	{
	padding:8px 12px 8px 8px;
	text-align:justify;
	}

#rightCol
	{
	float:left;width:930px;text-align:left;padding:16px 0px 0px 8px;margin:0px 0px 0px 0px;
	color:#772222;font-size:16px;line-height:22px;
	background-color:#EEEEEE;
	}
	
#footer
	{
	font-size:14px;font-family:sans-serif;width:1200px;margin:48px auto 0px auto;border:solid;border-color:#660000;border-width:4px 0px 0px 0px;
	}
	
.footerArea
	{
	float:left;padding:16px 11px 16px 11px;line-height:24px;text-align:left;width:110px;
	}
	
.footerArea:hover
	{
	background-color:#772222;
	}

.footerArea a
	{
	text-decoration:none;color:#FFCCCC;
	padding:2px 2px 2px 8px;
	}
.footerArea a:hover
	{
	background-color:#AA2222;
	color:#FFFFFF;
	}


	
.footerSubAreaTop
	{
	color:#FFFFFF;
	font-size:24px;
	border:solid;
	border-width:0px 0px 1px 0px;
	}
	
.footerSubAreaTop a
	{
	text-decoration:none;color:#FFFFFF;
	}
	
.clearBoth
	{
	clear:both;
	}

.title_top
	{
	font-size:24px;
	color:#FFFFFF;
	text-align:left;
	padding-left:16px;
	padding-top:8px;
	padding-bottom:8px;
	margin-bottom:8px;
	
	background: #772222; /* Old browsers */
	background: -moz-linear-gradient(left,  #772222 0%, #ce603b 68%, #d3763d 100%); /* FF3.6+ */
	background: -webkit-gradient(linear, left top, right top, color-stop(0%,#772222), color-stop(68%,#ce603b), color-stop(100%,#d3763d)); /* Chrome,Safari4+ */
	background: -webkit-linear-gradient(left,  #772222 0%,#ce603b 68%,#d3763d 100%); /* Chrome10+,Safari5.1+ */
	background: -o-linear-gradient(left,  #772222 0%,#ce603b 68%,#d3763d 100%); /* Opera 11.10+ */
	background: -ms-linear-gradient(left,  #772222 0%,#ce603b 68%,#d3763d 100%); /* IE10+ */
	background: linear-gradient(to right,  #772222 0%,#ce603b 68%,#d3763d 100%); /* W3C */
	filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#772222', endColorstr='#d3763d',GradientType=1 ); /* IE6-9 */

	}
.title_bot
	{
	font-size:22px;
	background-color:#772222;
	color:#d3763d;
	padding:8px;
	border-radius:16px;
	width:50%;
	margin:auto;
	text-align:center;
	}
.title_top,.title_bot,p.mainP,.footerArea,.desc
	{
	font-family: 'Pathway Gothic One', sans-serif;
	}
p.mainP,.bodyP
	{
	font-size:20px;
	line-height:28px;
	padding:0px 16px 0px 16px;
	}
.desc
	{
	font-size:20px;
	line-height:30px;
	text-align:justify;
	width:430px;
	padding:16px;
	}
.descLeft
	{
	font-size:20px;
	line-height:30px;
	text-align:justify;
	width:450px;
	padding:16px;
	float:left;
	display:block;
	}
.descBreak
	{
	clear:both;
	background-color:#CCCCCC;	
	height:2px;
	width:920px;
	margin:8px 0px 84px 0px;
	}
.descBreakTiny
	{
	clear:both;
	background-color:#CCCCCC;	
	height:2px;
	width:920px;
	margin:8px 0px 8px 0px;
	}	
	
.col400
	{
	width:440px;
	float:left;
	padding:0px 8px 8px 12px;
	}
li
	{
	line-height:24px;
	font-size:20px;
	padding:4px 0px 4px 0px;
	}
li:hover
	{
	background-color:#CCCC00;
	}
.vidObj
	{
	float:left;
	margin:4px;
	}
#bCopyL,#bCopyR
	{
	width:450px;
	float:left;
	padding:5px;
	}
.ex	
	{
	float:left;
	padding:16px 24px 16px 24px;
	font-size:32px;
	}
.ex img
	{
	display:block;
	padding:32px 0px 8px 0px;
	}
.clearDiv
	{
	clear:both;
	border:solid;
	border-width:2px 0px 0px 0px;
	border-color:#000000;
	height:2px;
	width:910px;
	}
.galItem
	{
	float:left;
	background-color:#FFFFFF;
	border-radius:16px;
	margin:16px;
	}