PHP - Time Zone Problem
Hi
My code was working perfectly when my hosting company located in Japan. But i transfer to US(hostgator) and now my time zone changes asia/tokyo to America/Chicago. Therefore, all my codes, scripts and sites are following one day behind of Japan local time. Great appreciate for any help. My code is below: <?php $host = "localhost"; $user = "user"; $pass = "pass"; $data = "mysql_db"; $cn = mysql_connect($host, $user, $pass) or trigger_error(mysql_error(),E_USER_ERROR); mysql_select_db($data, $cn) or die("Could not Connect Database Please Try again later !!!"); mysql_query("set names utf-8", $cn); if(date("H:i:s") < '03:00:00') // Changes midnight 00:00:00 to 03:00:00 $midnight = 1; else $midnight = 0; $TODAY__ = mktime(0, 0, 0, date("n"), date("d") - $midnight, date("Y")); date_default_timezone_set('Asia/Tokyo'); ?> Similar TutorialsHello, I tried to implement some PHP code to enable a web page to show "Dinner" specials versus "Lunch" specials based on the time. The business is located in the Eastern Time Zone, so I only need to routine to work based on Eastern Time (New York). What I am noticing is that the server is processing the lines of code so fast that the command to establish the correct time for the remaining code is not always being acknowledged. This line of code appears to be processing too fast for the remaining lines of code: date_default_timezone_set ( "America/New_York" ); Is there some additional code I can put in place to make sure the correct time is always ascertained? I need the $hourmin variable to always return a combination of hour + minute based on 24-hour time and Eastern Time zone. My code is as follows: <?php $name8 = file_get_contents("test/special8name.txt"); date_default_timezone_set ( "America/New_York" ); $gethour = date("H"); $getminutes = $gettimedate["minutes"]; $gettimedate = date(); $hourmin = $gethour . $getminutes; $currentday = date("l", time()); $currentdate = date("M j, Y"); if ($hourmin < 1500 && $currentday <> "Saturday" && $currentday <> "Sunday") { echo "<span class=\"namesred\">$name8 </span>"; } else if ( $hourmin > 1500 && $hourmin < 2300 && $currentday <> "Saturday" && $currentday <> "Sunday") { echo "<span class=\"namesblue\">$name8 </span>"; } else if ( $currentday == "Saturday" or $currentday == "Sunday") { echo "<span class=\"namesblue\">$name8 </span>"; } ?> Having a problem since the time change of 1 hour. Times now show 2:08 when it is 3:08 I am using: Code: [Select] date_default_timezone_set('EST'); date('g:i a'); Any way to fix this to show corrent time? How to set the time zone? All 3 shows the same time??? <?php date_default_timezone_set("Australia/Melbourne"); echo "time=" . time(); ?> <?php echo "time=" . time(); ?> <?php date_default_timezone_set("Antarctica/Palmer"); echo "time=" . time(); ?> I am sorry I have absolutely no idea where this question fits in this forum bcoz its related to PHP , MySQL and Javascript... So here is my question .. I use MySql database to store posts.. where 'postdate and time' is saved using 'CURRENT_TIMESTAMP' of MySql that offcourse gives "2010-08-31 09:47:10" format... When I have to calculate when the post was posted just before loading the posts on users wall e.g. "2 min ago"... I take the 'postdate and time' from database then use strtotime() function in php to convert it to string you know since jan 1 1970. Now this time stamp is sent to javascript function which uses 'Date' Object to create current time and then 'getTime' to get the string like one Mentioned earlier. it then calculates the difference and displays it.. Just to inform you.. I used javascript to I may refresh "posted since" periodically using "SetInterval()" But the problem here arises. There is difference of 1 Hour and 24 Sec in both times....... Sorry If I confused you... But the problem is simple. In javascript date object and MySql --> strtotime() there is time difference... How I can correct it ??? please Help ... Codes: 1. function to convert str to time function change($date){ $time_early=strtotime($date); return $time_early; } 2. javascript Code to check "Post Since" function calc_difference() { $("[name=posttime]").each(function() { var current=$(this).attr("id"); localtimevalue = new Date(); d = localtimevalue.getTime(); var d= parseInt(d)/1000; var diff=d-parseInt(current); var diff=parseInt(diff); var min=parseInt(diff/60); var hours=parseInt(diff/3600); var days=parseInt(diff/86400); var months=parseInt(diff/2592000); var years=parseInt(diff/31104000); if( min==0 ){ $(this).text("Posted: "+diff +" seconds ago "); } if(min>0 && hours==0 && days==0 && months==0){ if(min==1){ $(this).text("Posted: a minute ago "); }else{ $(this).text("Posted: "+min +" minutes ago "); } } if(min>0 && hours>0 && days==0 && months==0){ if(hours==1){ $(this).text("Posted: an hour ago "); }else{ $(this).text("Posted: "+hours +" hours ago "); } } if(days>0 && months==0 && years==0){ if(days==1){ $(this).text("Posted: a day ago "); }else{ $(this).text("Posted: "+days +" days ago "); } } if(months>0 && years==0 ){ if(months==1){ $(this).text("Posted: a month ago "); }else{ $(this).text("Posted: "+months +" months ago "); } } if(years>0){ if(years==1){ $(this).text("Posted: a year ago "); }else{ $(this).text("Posted: "+years +" years ago "); } } }); } Javascript function is called on load and Jquery's .each function is used to update all post's time. I am trying to get local date/time. In my php file I am setting my timezone using $timezone = "America/Toronto"; putenv ('TZ=' . $timezone); Then I use the following to get current date and time print_r (getdate()); but my date displays in GMT, What am I doing wrong? As in the code above I am in Toronto and I need EST. By using the function date_default_timezone_set() I am trying to set my timezone. Do I have to change anything else in any other files like php.ini? Are time zones when calling the date function automatically decided based on where you live? Or is that something that I have to implement--Because the time is wrong according to my time zone. I have all the dates stored in my database as UTC and I want to retrieves these UTC date/time to show the local time zone. So, example, If I live in New York, I want it to show east coast time zone and not the Universal Time. Any idea? Purpose: To get time zone of a remote file in my time zone. I have to download a file daily (mp3, don't worry its legal!) from BBC. Problem is that sometimes BBC doesn't update the file and i have to download entire file to check if it has been updated or not. Hence i decided to code a page that gives me date and time of that remote file. I have successfully compiled the code (that i got from internet). But the time returns in EST. I want the time in IST (indian std time Asia/Calcutta). CURLINFO_FILETIME has bee used. Below is code. Pls suggest me how to convert EST to IST - Warning: I am a newbie. But i can follow instructions Code: [Select] <?php $curl = curl_init('http://wsdownload.bbc.co.uk/hindi/tx/32mp3/din_bhar.mp3'); //don't fetch the actual page, you only want headers curl_setopt($curl, CURLOPT_NOBODY, true); //stop it from outputting stuff to stdout curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // attempt to retrieve the modification date curl_setopt($curl, CURLOPT_FILETIME, true); $result = curl_exec($curl); if ($result === false) { die (curl_error($curl)); } $timestamp = curl_getinfo($curl, CURLINFO_FILETIME); if ($timestamp != -1) { //otherwise unknown echo "BBC Hindi was last modified" . date("d-m-Y h:i:s A T", $timestamp); //etc } ?> I have used it with custom getRemoteFileSize function he - Code: [Select] http://island.web44.net/bbc.php Hello Everyone, I am on windows server and In my ini file server time zone declared as below
[server_settings] but my application installed on another timezone eg: 'America/Los_Angeles' time zone. using date_default_timezone_get() i am always getting Europe/London timezone as it's declared in ini file. How to get local timezone(wherever application is installed) here? Thanks Krish Hi.. I got an issue in getting the total time. I have this code to get the sum of total time: Code: [Select] $result = mysql_query("INSERT INTO payroll.casual_hours(EMP_NO, Hours) SELECT EMP_NO, sec_to_time(SUM(time_to_sec(Rendered))) FROM payroll.casual_att WHERE DATE_FORMAT(LOGOUT, '%W') IN ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') GROUP BY EMP_NO") or die(mysql_error()); Rendered: 09:00:00 09:00:00 09:00:00 08:00:00 08:00:00 07:48:00 and the result of this is 50:48 but I need result is 50:80 the minutes is divided to 60 Is there any way to get the 50:80 result. Thank you so much.. Hi, I'm preparing a code for an automated email, but the date time is not working correctly. I wanted to do a cron scheduler that emails people twice a day - 9am and 9pm. 9am sends email about records logged starting 9pm yesterday to 9am, while 9pm sends email about records logged from 9:01am to 9:00pm. The database uses date/time, so I was doing an if statement of date time, but I wasn't getting the result I wanted. Sometimes the $now time is not within the yesterday 9pm to the 9pm today range. I don't know what I'm doing wrong, but I'm sure that it has something to do with the if statement, as the some of the $now time enters the else statement Here is my code: <?php $today = date('Y-m-d 00:00:00'); $nineyesterday = date('Y-m-d H:i:s', mktime(date("H") - (date("H") + 6), date("i") - date("i"), date("s") - date("s"), date("m") , date("d"), date("Y"))); $now = date('Y-m-d H:i:s', mktime(date("H") + 13, date("i"), date("s"), date("m") , date("d"), date("Y"))); $nineam = date('Y-m-d 09:00:00'); $nine30 = date('Y-m-d 09:30:00'); $ninepm = date('Y-m-d 18:00:00'); echo '9pm yesterday: '.$nineyesterday; echo '<br/>'; echo '9am: '.$nineam; echo '<br/>'; echo '9pm: '.$ninepm; echo '<br/>'; echo 'now: '.$now; echo '<br/>'; if ((strtotime($now) > strtotime($nineyesterday)) and (strtotime($now) <= strtotime($nineam))) { //count the answers by yes or no echo 'am'; } elseif ((strtotime($now) > strtotime($nineam)) and (strtotime($now) <= strtotime($ninepm))) { //count the answers by yes or no echo 'pm'; } else { echo 'error'; } ?> Thanks in advance ok so im wondering if you all could prob fix this code its not working and when "meta"when it refreshes the page nothing deletes Code: [Select] <?php $host="localhost"; // Host name $username="username"; // Mysql username $password="password"; // Mysql password $db_name="database name"; // Database name $tbl_name="table name"; // Table name // below was a replie from forums. it made alot of problems// foreach($_POST['checkbox'] AS $ID) { $values[] = '\''.intval($ID).'\''; } $values = implode(' , ',$values); $myQuery = "DELETE FROM $tbl_name WHERE id IN ($values)"; if(mysql_query($myQuery)) { header('Location: delete_multiple.php'); } else { echo 'Query failed: "'.$myQuery.'"'; } // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <style> /*table affects look of the whole table look */ table { margin-left: auto; margin-right: auto; border: 1px solid #330000; border-collapse:collapse; width:70%; border-width: 5px 5px 5px 5px; border-spacing: 1px; border-style: outset outset outset outset; border-color: #330000 #330000 #330000 #330000; border-collapse: separate; background-color: #330000; #800517 f535aa #330000 school color #9A0000 school color2 #991B1E school color3 #CCCC99 school color4 #9A0000 } /*th is table header */ th { text-align: left; height: 2.5em; background-color: #330000; color: #FC0; font-size:1.5em; } /*td is table data or the cells below the header*/ td { text-align: left; height:1.0em; font-size:1.0em; vertical-align:bottom; padding:10px; border-width: 5px 5px 5px 5px; padding: 8px 8px 8px 8px; border-style: outset outset outset outset; border-color: #9A0000 #9A0000 #9A0000 #9A0000; background-color: #CCCC99; -moz-border-radius: 0px 0px 0px 0px; } </style> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Pick Which Rows you want to delete, Then press delete.</strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td> <td align="center" bgcolor="#FFFFFF">delete</td></tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['name']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <?php // Check if delete button active, start this // edited if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">"; } } mysql_close(); ?> </table> </form> </td> </tr> </table> this is whats wrong with it could i get some help? Warning: Invalid argument supplied for foreach() in /home/sumersadl/public_html/testfile/delete_multiple.php on line 8 Warning: implode() [function.implode]: Invalid arguments passed in /home/sumersadl/public_html/testfile/delete_multiple.php on line 12 Warning: mysql_query() [function.mysql-query]: Access denied for user 'root'@'localhost' (using password: NO) in /home/sumersadl/public_html/testfile/delete_multiple.php on line 16 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/sumersadl/public_html/testfile/delete_multiple.php on line 16 Query failed: "DELETE FROM test_mysql WHERE id IN ()" Hi - I have been searching for a way to select the stored time from a database (stored in 24h format - 13:20:00) and display it as 12h format. I have checked a number of forums and nothing quite seems to fit the bill. I would like it to display as 2:00pm, 12:00am, etc. Here is what I have so far: $sql = ('SELECT * FROM events WHERE active="1" AND event_date >= CURRENT_DATE AND MONTH(event_date) = 1 order by event_date ASC, event_start ASC'); $result = mysql_query($sql); $num_rows = mysql_num_rows($result); // Yes Item if (!($num_rows == 0)) { $myrow = mysql_fetch_array($result); echo ('<span class="bold" style="font-size:14px">January</span>'); do { printf ('<span>Event Time: %s', $myrow['event_start']); if ($myrow['event_end'] != '') { printf (' to %s', $myrow['event_end']); } } while ($myrow = mysql_fetch_array($result)); } Right now this just shows the regular 24h format (hh:mm:ss) for any events in the month of January. I would like both "event_start" and "event_end" to show up in 12h format. I have tried a number of things but none of it works. I'm SURE it is something simple that I have missed. Thanks in advance for any help. So the code works right, (I think) but for some reason the way I built it the logic comes back null. I can do All w a specific shift/s, and All with department/s but I can't do All shifts and All departments it doesn't' error either, just brings back nothing, maybe timing out? I'm very new at this so I apologize in advance. Code below ############################################################ <form method="post" action=""> <br><br> <table bordercolor="yellow" border="2"> <tr><td class="line"><b>Start Date:</b></td><td> <input type="text" name="startdate" value="mm/dd/yyyy" /></td></tr> </tr> <tr><td class="line"><b>End Date:</b></td><td> <input type="text" name="enddate" value="mm/dd/yyyy" /></td></tr> </tr> <tr><td class="line"><b>Shift:</b></td><td> <SELECT NAME="shift" > <option selected>Select Shift</option> <option>First</option> <option>Second</option> <option>Third</option> <option>All</option> </SELECT> </td></tr> <tr><td class="line"><b>Department:</b></td><td> <SELECT NAME="department" > <option selected>Select Department</option> <option>Advanced Hosting Support</option> <option>Server Support</option> <option>Managed Support</option> <option>All</option> </SELECT> </td></tr> </tr> </tr> </table> <br><br> <input type="submit" value="submit" /> </form> <form action="" method="post"> </form> </html> <?php require_once('global.inc.php'); class DataLogic { //function to obtain Employee names from RealID array to pass to MSSQL for call count function GetEmpNames ($RealID) { global $ems_db_connect; foreach ($RealID as $emplist){ $query1 = mysql_query ("SELECT FirstName, LastName FROM ems_employee_list WHERE RealID=$emplist", $ems_db_connect) or die(mysql_error());; while($row = mysql_fetch_array($query1)) { $FirstName[] = $row['FirstName']; $LastName[] = $row['LastName']; } } $friendlyname = array('first_name' => $FirstName, 'last_name' =>$LastName); return $friendlyname; } //function to display Employee names from RealID array obtained from department and shift function DisplayEmpNames ($RealID) { global $ems_db_connect; foreach ($RealID as $emplist){ $query1 = mysql_query ("SELECT FirstName, LastName FROM ems_employee_list WHERE RealID=$emplist", $ems_db_connect) or die(mysql_error());; while($row = mysql_fetch_array($query1)) { $FirstName = $row['FirstName']; $LastName = $row['LastName']; $fullname[] = "$LastName, $FirstName"; } } return $fullname; } //function to pull the RealID's of Employees based on shift //Returns a list of RealID's for use with GetIris and RepSort functions function SelectEmpShift ($key) { global $ems_db_connect; switch($key) { case "First": $shift = 1; break; case "Second": $shift = 2; break; case "Third": $shift = 3; break; default: $shift = 4; } if ($shift == 4){ $query1 = mysql_query ("SELECT RealID FROM ems_employee_list LEFT JOIN ems_employee_schedules USING (EmployeeID) WHERE RealID > 0 AND Department='AHS'", $ems_db_connect) or die(mysql_error()); while ($row = mysql_fetch_array($query1)) { $x[]=$row['RealID']; } } else { $query1 = mysql_query ("SELECT RealID FROM ems_employee_list LEFT JOIN ems_employee_schedules USING (EmployeeID) WHERE RealID > 0 AND Shift = $shift AND Department ='AHS'", $ems_db_connect); while ($row = mysql_fetch_array($query1)) { $x[]=$row['RealID']; } } return $x; } //Function to Select Employees based on Department function SelectEmpDep ($key) { global $ems_db_connect; switch($key) { case "Managed Support": $deptcode = 6; break; case "Server Support": $deptcode = 5; break; case "Advanced Hosting Support": $deptcode = 2; break; default: $deptcode = 7; } if ($deptcode == 7){ $query1 = mysql_query ("SELECT RealID FROM ems_employee_list LEFT JOIN ems_employee_schedules USING (EmployeeID) WHERE RealID > 0 AND Department='AHS'", $ems_db_connect) or die(mysql_error()); while ($row = mysql_fetch_array($query1)) { $x[]=$row['RealID']; } } elseif ($deptcode == 5){ $query1 = mysql_query ("SELECT RealID FROM ems_employee_list LEFT JOIN ems_employee_schedules USING (EmployeeID) WHERE RealID > 0 AND AccessID=5 OR AccessID=3 AND Department='AHS' AND RealID >0", $ems_db_connect) or die(mysql_error()); while ($row = mysql_fetch_array($query1)) { $x[]=$row['RealID']; } } else { $query1 = mysql_query ("SELECT RealID FROM ems_employee_list LEFT JOIN ems_employee_schedules USING (EmployeeID) WHERE RealID > 0 AND AccessID=$deptcode AND Department ='AHS' ", $ems_db_connect); while ($row = mysql_fetch_array($query1)) { $x[]=$row['RealID']; } } return $x; } //function to sort Shift by multiple Deparments function RepSortShiftDept ($RealIDShift, $RealIDDepartment='', $RealIDDepartment2='') { $deptnumber = func_num_args(); if ($deptnumber == 1) { $result = $RealIDShift; } elseif ($deptnumber == 2) { $result = array_intersect($RealIDShift, $RealIDDepartment); } else { $result = array_intersect($RealIDShift, array_merge($RealIDDepartment, $RealIDDepartment2)); } return $result; } //function to sort Department by multiple Shifts function RepSortDeptShift ($RealIDDepartment, $RealIDShift='', $RealIDShift2='') { $shiftnumber = func_num_args(); if ($shiftnumber == 1) { $result = $RealIDDepartment; } elseif ($shiftnumber == 2) { $result = array_intersect($RealIDDepartment, $RealIDShift); } else { $result = array_intersect($RealIDDepartment, array_merge($RealIDShift, $RealIDShift2)); } return $result; } //Function to get and display count of Iris tickets from a date rage. //$RealID needs to be an array of EmployeeIDs obtained from SelectEmpShift, SelectEmpDepart, and RepSort functions function GetIris($RealID, $startdate, $enddate) { global $hocstat_db_connect; foreach ($RealID as $emplist){ $mssqlquery = "SELECT COUNT (IncidentID) AS mycount FROM hocstats.dbo.DailyStatsEmployee WHERE hocstats.dbo.DailyStatsEmployee.EmployeeID=$emplist AND(hocstats.dbo.DailyStatsEmployee.DateModified BETWEEN '$startdate 00:00:00.000' AND '$enddate 23:59:59.000')"; $query_3 = mssql_query ($mssqlquery, $hocstat_db_connect); $row =(mssql_fetch_array($query_3)) ; $iriscount[] = $row['mycount']; } return $iriscount; } //Function to get and display call counts from a date range. For use with GetEmpName ONLY function GetCalls ($friendlyname, $startdate, $enddate) { global $hocstat_db_connect; for ($x = 0; $x < count ($friendlyname['last_name']); $x++) { $query1 ="SELECT ISNULL(SUM(CallsHandledToHalf), 0) AS calls FROM Agent_Skill_Group_Half_Hour ASGHH WITH (NOLOCK) INNER JOIN dbo.agent ON ASGHH.skilltargetid = dbo.agent.skilltargetid WHERE(dbo.agent.enterprisename = 'HOC_{$friendlyname['last_name'][$x]}_{$friendlyname['first_name'][$x]}' OR dbo.agent.enterprisename = '{$friendlyname['last_name'][$x]}_{$friendlyname['first_name'][$x]}') AND (ASGHH.datetime BETWEEN '$startdate 00:00:00' AND '$enddate 23:59:00')"; $mssqlquery = mssql_query ($query1, $hocstat_db_connect); while ($row =(mssql_fetch_array($mssqlquery))) { $callcount[] = $row['calls']; } } return $callcount; } }//class close if($_POST) //setting varibles from form input { $shift_id= isset($_POST['shift']) ? trim($_POST['shift']) : die('Missing entry: Shift Selection'); $start_date= isset($_POST['startdate']) ? trim($_POST['startdate']) : die('Missing enty: Start Date'); $end_date= isset($_POST['enddate']) ? trim($_POST['enddate']) : die('Missing enty: End Date'); $depart_id= isset($_POST['department']) ? trim($_POST['department']) : die('Missing entry: Shift Selection'); } echo "You have selected stats for $shift_id shift(s) and $depart_id department(s) from $start_date to $end_date. </br>" ; $test=new DataLogic(); $calls = $test->GetCalls($test->GetEmpNames($test->RepSortShiftDept($test->SelectEmpShift("$shift_id"), $test->SelectEmpDep("$depart_id"))), $start_date, $end_date); $iris= $test->GetIris ($test->RepSortShiftDept($test->SelectEmpShift("$shift_id"), $test->SelectEmpDep("$depart_id")), $start_date, $end_date); $name= $test-> DisplayEmpNames($test->RepSortShiftDept($test->SelectEmpShift("$shift_id"), $test->SelectEmpDep("$depart_id"))); $table = array ( 'calls' => $calls, 'iris' => $iris, 'name' => $name); for ($x = 0; $x < count ($table['calls']); $x++) { echo $table["name"][$x]; echo "</br> Calls Taken :"; echo $table["calls"][$x]; echo "</br> Iris Tickets Resolved:"; echo $table["iris"][$x]; echo "</br>"; } ?> Okay here's the simple thing I'm trying to do. I have a time in a db on my server .. let's say its March 1st 2011 at 12:00AM. This time is dynamically set by the server, so it's on server time. Now, lets say today is Feb 28th 2011 at 12:00AM on the server. I'm trying to write a dynamic script that will count down that time .. in this case I would want to show 23:59:59. Every count down script i've found online gives me an option to use local time (browser) or server time. Each time i plug in server time it is always set to my browse time ... I echo everything out and I basically get this: Server time: Feb 28th 2011 at 12:00AM My browser time: Feb 28th 2011 at 2:00AM Script time remaining: 21:59:59 So why does this keep happening? When I echo the date() from the server it's always 2 hours ahead of my time but the script never adjusts. Any ideas or does anyone know of a good working script? I'm on eastern time and the server is on pacific. Here's my last try, you'll see I place the php date into this towards the bottom but I've also tried jquery and SSI methods too. <!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" /> <title>Untitled Document</title> </head> <body> <script language="JavaScript"> TargetDate = "2/1/2011 12:00 AM"; BackColor = "palegreen"; ForeColor = "navy"; CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds."; FinishMessage = "It is finally here!"; </script> <script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"> */ function calcage(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString(); if (LeadingZero && s.length < 2) s = "0" + s; return "<b>" + s + "</b>"; } function CountBack(secs) { if (secs < 0) { document.getElementById("cntdwn").innerHTML = FinishMessage; return; } DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000)); DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24)); DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60)); DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60)); document.getElementById("cntdwn").innerHTML = DisplayStr; if (CountActive) setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod); } function putspan(backcolor, forecolor) { document.write("<span id='cntdwn' style='background-color:" + backcolor + "; color:" + forecolor + "'></span>"); } if (typeof(BackColor)=="undefined") BackColor = "white"; if (typeof(ForeColor)=="undefined") ForeColor= "black"; if (typeof(TargetDate)=="undefined") TargetDate = "12/31/2020 5:00 AM"; if (typeof(DisplayFormat)=="undefined") DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds."; if (typeof(CountActive)=="undefined") CountActive = true; if (typeof(FinishMessage)=="undefined") FinishMessage = ""; if (typeof(CountStepper)!="number") CountStepper = -1; if (typeof(LeadingZero)=="undefined") LeadingZero = true; CountStepper = Math.ceil(CountStepper); if (CountStepper == 0) CountActive = false; var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990; putspan(BackColor, ForeColor); var dthen = new Date(TargetDate); var dnow = new Date("<!--config timefmt='%c' --><!--echo var='DATE_LOCAL' -->"); if(CountStepper>0) ddiff = new Date(dnow-dthen); else ddiff = new Date(dthen-dnow); gsecs = Math.floor(ddiff.valueOf()/1000); CountBack(gsecs); </script> <br /> <?php $now = new DateTime(); echo $now->format("M j, Y H:i:s O")."\n"; ?> </body> </html> Hi guys i am facing a problem in my php code and i dont know how to figure out so i search on google and i have started searching for a php forums and i found this community. The problem is i made three pages in page1 i create a simple form with one text field and add two buttons one name is "add more fields" and one is "submit" when i click on add more fields button a text field is generate by using javascript functions. Let say i create 3 fields and enter names and submit the form by having form action "page2" In page2 i just simply get all values i entered in fields and print them on screen and also there is a link of "page3" that says edit your information and the session is start. In "page3" i made changes to values and submit them again again. Its all working. But i i also want "add more fields" button in page3 so that i can generate more fields also on page3 and this this the point where i stucked and i didn't figure out how can i do this task to create add more fields button. Can you guys help me in this regard thanks. Page1 Code: Code: [Select] <!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> <script> function addonemore() { var tot = document.getElementById('count').value; tot = parseInt(tot)+1; document.getElementById('count').value=tot; var newhtml = 'student '+tot+' <input type="text" name="val'+tot+'" id="val'+tot+'" /><br/>'; document.getElementById('mydiv').innerHTML += newhtml; } </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="page2.php" method="post" enctype="application/x-www-form-urlencoded"> student 1 <input type="text" name="val1" id="val1" /> <div id="mydiv"></div> <input type="button" id="addnew" name="addnew" value="Add more" onclick="addonemore()" /> <input type="submit" id="submit" name="submit" value="submit" /> <input type="hidden" name="count" id="count" value="1" /> </form> </body> </html> Page2 Code: Code: [Select] <?php session_start(); $_SESSION['count'] = $_REQUEST['count']; for($i=1;$i<=($_REQUEST['count']);$i++) { $html .= 'student '.$i.':'.$_REQUEST['val'.$i].'<br/>'; $_SESSION['val'.$i] = $_REQUEST['val'.$i]; } echo $html; echo "<br/><a href='page3.php'>click here to edit</a>"; ?> Page3 Code: Code: [Select] <html> <head> <script> function addonemore() { var tot = document.getElementById('count').value; tot = parseInt(tot)+1; document.getElementById('count').value=tot; var newhtml = 'student '+tot+' <input type="text" name="val'+tot+'" id="val'+tot+'" /><br/>'; document.getElementById('mydiv').innerHTML += newhtml; } </script> </head> <body> <?php session_start(); $html = '<form action="page2.php" method="post" enctype="application/x-www-form-urlencoded">'; for($i=1;$i<=($_SESSION['count']);$i++) { $html .= 'student '.$i.':<input type="text" name="val'.$i.'" id="val'.$i.'" value="'.$_SESSION['val'.$i].'" />'; } $html .='<input type="submit" id="submit" name="submit" value="submit" /><input type="hidden" name="count" id="count" value="'.$_SESSION['count'].'" /></form>'; echo $html; ?> <?php $html = '<form action="" method="post" enctype="application/x-www-form-urlencoded">'; $html .= '<input type="button" id="addnew" name="addnew" value="Add more" onclick="addonemore()" /></form>' ?> </body> </html> Ok first of all I want to apologize for asking what I'm about to ask. I understand it should be some stupidly easy to find mistake but considering the fact I have to send the code tomorrow leaves me with little to no time to try and find the solution so I'll be asking here and hope that by the time I wake up tomorrow an answer will be here and I'll be able to resume scripting. So my problem is that I just can't find how to make php commands run at all. I tried just randomly inserting them into my html code then found out it needs a separate file. So I created the basic.php with this code: <html> <body> <?php echo "Hello World"; ?> <div>adgaeganerhaohn</div> </body> </html> tried opening it through a form in my html code but it wouldn't print the Hello world line, then I tried running it straight into firefox but I only got adgaeganerhaohn again (without that line I get a white page) So I need to know what am I doing wrong? I have php5.301 installed with default options (no server). thanks for your help beforehand, once I get a bit more into php I'll be coming back with serious questions but for now I really need someone to tell me how php is supposed to work and what I'm doing wrong hey there i am new on this forum yea basicly when im sending more than 3-500 mails at a time the subject changes to "unknown" and the $from also changes to unknown :/ could anyone explain this ? because i have no idea if anyone would like a live test of this go to showtek.net23.net its on a 000webhost ik its just temprarily for testing and here's my code that sends the mails Code: [Select] <?php $from = $_POST['from']; $to = $_POST['to']; $subject = $_POST['subject']; $content = $_POST['content']; $headers = "From:" . $from; $myFile = "mails.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = $myfile; fwrite($fh, $stringData); fclose($fh); $email_list = file("mails.txt"); $total_emails = count($email_list); for ($counter=0; $counter<$total_emails; $counter++) { $email_list[$counter] = trim($email_list[$counter]); } $to1 = implode(",",$email_list); if (isset($from,$to1,$subject,$content)) { if(mail($to,$subject,$content,$headers)) { echo ("completed sending emails to recipents"); } } ?> |