PHP - Daylight Savings Time Screwed Up Code
Hey everyone,
So I've been using this code for a while and it may not be the best way of doing things but its worked for me based on my very limited knowledge of PHP. The code is based for a radio station which makes an image change based on the day and time. For some reason though due to daylight savings time ending the code is now off an hour. Whats the best way of fixing this without changing every single number? (Which I actually did try and still seem to be screwing it up) Below is the code:
<p> <?php $h = date('G'); //set variable $h to the hour of the day $d = date('w'); //set variable $d to the day of the week. $year = date('Y'); //set variable $year to the current year // SUNDAY SCHEDULE if ($d == 0 && $h >= 4 && $h < 5) $img = '/images/shows/HughHewitt.png'; else if ($d == 0 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 0 && $h >= 10 && $h < 11) $img = '/images/shows/MomTalk.png'; else if ($d == 0 && $h >= 11 && $h < 12) $img = '/images/shows/GoodParenting.png'; else if ($d == 0 && $h >= 12 && $h < 14) $img = '/images/shows/PetShow.png'; else if ($d == 0 && $h >= 14 && $h < 15) $img = '/images/shows/GardenRebel.png'; else if ($d == 0 && $h >= 15 && $h < 16) $img = '/images/shows/WorkingMother.png'; else if ($d == 0 && $h >= 16 && $h < 17) $img = '/images/shows/WhatsCooking.png'; else if ($d == 0 && $h >= 17 && $h < 18) $img = '/images/shows/HomeWizards.png'; else if ($d == 0 && $h >= 18 && $h < 19) $img = '/images/shows/DougStephan.png'; else if ($d == 0 && $h >= 19 && $h < 20) $img = '/images/shows/Finance.png'; else if ($d == 0 && $h >= 20 && $h < 21) $img = '/images/shows/PopularScience.png'; else if ($d == 0 && $h >= 21 && $h < 22) $img = '/images/shows/ABCRadio.png'; else if ($d == 0 && $h >= 22) $img = '/images/shows/Medicine.png'; else if ($d == 1 && $h >= 0 && $h < 3) $img = '/images/shows/ArmedAmerica.png'; else if ($d == 1 && $h >= 3 && $h < 4) $img = '/images/shows/HughHewitt.png'; // MONDAY SCHEDULE if ($d == 1 && $h >= 4 && $h < 5) $img = '/images/shows/HughHewitt.png'; else if ($d == 1 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 1 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 1 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 1 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 1 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 1 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 1 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 2 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 2 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 2 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // TUESDAY SCHEDULE if ($d == 2 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 2 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 2 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 2 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 2 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 2 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 2 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 2 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 3 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 3 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 3 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // WEDNESDAY SCHEDULE if ($d == 3 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 3 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 3 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 3 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 3 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 3 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 3 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 3 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 4 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 4 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 4 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // THURSDAY SCHEDULE if ($d == 4 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 4 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 4 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 4 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 4 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 4 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 4 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 4 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 5 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 5 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 5 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // FRIDAY SCHEDULE if ($d == 5 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 5 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 5 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 5 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 5 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 5 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 5 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 5 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 6 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 6 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 6 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // SATURDAY SCHEDULE if ($d == 6 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 6 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 6 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 6 && $h >= 10 && $h < 12) $img = '/images/shows/HaidtReport.png'; else if ($d == 6 && $h >= 12 && $h < 13) $img = '/images/shows/ABCNews.png'; else if ($d == 6 && $h >= 13 && $h < 16) $img = '/images/shows/GarySullivan.png'; else if ($d == 6 && $h >= 16 && $h < 18) $img = '/images/shows/PopularTech.png'; else if ($d == 6 && $h >= 18 && $h < 19) $img = '/images/shows/WhatWorks.png'; else if ($d == 6 && $h >= 19 && $h < 21) $img = '/images/shows/JillMoney.png'; else if ($d == 6 && $h >= 21 && $h < 23) $img = '/images/shows/YouManual.png'; else if ($d == 6 && $h >= 23) $img = '/images/shows/MadeAmerica.png'; else if ($d == 0 && $h >= 0 && $h < 1) $img = '/images/shows/MensHealth.png'; else if ($d == 0 && $h >= 1 && $h < 2) $img = '/images/shows/AlanTaylor.png'; else if ($d == 0 && $h >= 2 && $h < 4) $img = '/images/shows/HughHewitt.png'; ?> <img src="<?php echo $img; ?>">Thank You! Kevin Similar TutorialsI wrote this bit of code to get the next six datetimes of a certain date. It was working perfectly until this week. Code: [Select] <?php $start = "2011-11-06"; $num_days = 6; for ($i = 0; $i <= $num_days; $i += 1) { $stamp = strtotime($start) + ($i * 86400); echo date('l - n/d/Y - h:i a',$stamp)."<br/>"; } ?> The 2011-11-06 is a Sunday so i would expect to get the following: Sunday - 11/06/2011 - 12:00 am Monday - 11/07/2011 - 12:00 am Tuesday - 11/08/2011 - 12:00 am Wednesday - 11/09/2011 - 12:00 am Thursday - 11/10/2011 - 12:00 am Friday - 11/11/2011 - 12:00 am Saturday - 11/12/2011 - 12:00 am instead it is producing: Sunday - 11/06/2011 - 12:00 am Sunday - 11/06/2011 - 11:00 pm Monday - 11/07/2011 - 11:00 pm Tuesday - 11/08/2011 - 11:00 pm Wednesday - 11/09/2011 - 11:00 pm Thursday - 11/10/2011 - 11:00 pm Friday - 11/11/2011 - 11:00 pm How should i go about fixing this so it doesn't happen again? Code: [Select] <?php if(date('w') == 0) $str = 'today'; else $str = 'last sunday'; $timestamp = strtotime($str); //echo $timestamp; echo "<img src='brn_masthead.gif' width='500' /><br /><table border='1'><tr>"; echo "<tr><td align='center' width='140'><b>Sunday</b></td><td align='center' width='140'><b>Monday</b></td><td align='center' width='140'><b>Tuesday</b></td><td align='center' width='140'><b>Wednesday</b></td> <td align='center' width='140'><b>Thursday</b></td><td align='center' width='140'><b>Friday</b></td><td align='center' width='140'><b>Saturday</b></td></tr><tr>"; $j = 0; for($i = 0; $i < 14; $i++) { $thisdate = date('Y-m-d', $timestamp + ($i * (60 * 60 * 24))); ?> I've looked into mktime and checked the manual, but can't find anything that seems to work inside the loop. Thanks! I'm using a time stamp where I'm getting the date and time from the database server rather than using a unix time stamp. Because I'm in a different time zone as the server, my time was always off by 1 hour. I fixed that problem by writing some code to adjust the hour of the time and the date depending on what time it was. It was working fine until a few weeks ago when I had to adjust my clock for daylight savings time... now the time is off by 2 hours because of that. Well, I fixed that and now it's working fine again. My question is does anyone know of a way to automatically determine whether or not I should be in daylight savings time or not so I can just use an if/else statement to keep the time adjusted properly rather than having to do it manually every time the time changes? Basically, I would like to do it something like the following: Code: [Select] <?php if ($daylightsavings = "y") { (adjust time/date for 1 hour difference); } else { (adjust time/date for 2 hour difference); } ?> Anyone have any ideas? Please help! User enters Date (that is somewhere in future, few hours or maybe few years). I need to store in MYSQL Date minus 6 hours keeping in mind daylight savings time. I tried to convert date to unix timestamp and subtract 6*60*60. Works great, but does not take into consideration daylight savings time. This is what I have for the form (in short version) along with the text area and submit button. The form shows up OK on the Internet http://www.lakegenevapieco.com/test_product_list.php The problem is when I fill it out & submit it doesn't do two things: 1) It doesn't E-Mail me the information 2) It doesn't say, Thank you for using our mail form. It actually says page not available. Here is the code: <html> <head> <meta http-equiv="Content-Language" content="en-us"> <title>Products to be listed on the web site for the month of</title> </head> <body> Products to be listed on the web site for the month of <select size="1" name="MONTH"> <option selected>PICK MONTH</option> <option>1-JANUARY</option> <option>2-FEBUARY</option> <option>3-MARCH</option> <option>4-APRIL</option> <option>5-MAY</option> <option>6-JUNE</option> <option>7-JULY</option> <option>8-AUGUST</option> <option>9-SEPTEMBER</option> <option>10-OCTOBER</option> <option>11-NOVEMBER</option> <option>12-DECEMBER</option> </select> <select size="1" name="YEAR"> <option selected>PICK YEAR</option> <option>2010</option> <option>2011</option> <option>2012</option> <option>2013</option> <option>2014</option> <option>2015</option> </select></p> <p><input type="checkbox" name="PumpkinSB" value="ON"> Pumpkin Price increase to <input type="text" name="PriceIncreaseTo151" size="20" value="$"></p> <p><input type="checkbox" name="PumpkinWalnutSB" value="ON"> Pumpkin Walnut Price increase to <input type="text" name="PriceIncreaseTo152" size="20" value="$"></p> <p><input type="checkbox" name="RaspberrySB" value="ON"> Raspberry Price increase to <input type="text" name="PriceIncreaseTo153" size="20" value="$"></p> <p> </p> <p> </p> <p> <?php function spamcheck($field) { //filter_var() sanitizes the e-mail //address using FILTER_SANITIZE_EMAIL $field=filter_var($field, FILTER_SANITIZE_EMAIL); //filter_var() validates the e-mail //address using FILTER_VALIDATE_EMAIL if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } } if (isset($_REQUEST['email'])) {//if "email" is filled out, proceed //check if the email address is invalid $mailcheck = spamcheck($_REQUEST['email']); if ($mailcheck==FALSE) { echo "Invalid input"; } else {//send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail("myemail@mia.net", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; } } else {//if "email" is not filled out, display the form echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?> </p> </form> </body> </html> Hello, I went to one of those paid sites to try and get help with a php project, the guy bid the job and worked for a few hours and then disappeared. Left me hanging and now I am turned off by trying to do that again so I have decided to try it myself.
So I have started over, and have gotten the front end of the website done, and having a few troubles with the admin end. So here is what I am doing...
Joomla 3.3
Ohanah Event Mgmt System
This system allows you to create events and add event photos, the system didnt allow descriptions to be added to those photos, which show on the front end and popup in a light box.
Here is a photo of the front end that is working now.
http://www.sbsracing...end-working.jpg
And here is the photo of the progress on the admin area, I have text fields added to each event photo once it is added. However I am having trouble coding the display and editing of the descriptions.
http://www.sbsracing.net/broken2.jpg
I believe this is only controlled by one file in the admin area. I have attached it to confirm this and will show the lines of code here that I think need to be changed.
First would be the add photo button area, which I havent figured out how to get the description there for, but would be ok adding descriptions after the photo was uploaded.
function createPicture() { if (eventPicture=="") { jQuery("#eventPicture").html('<table><tr><td><input id="selectPicture" type="button" class="button" value="<?=addslashes(@text('OHANAH_ADD_PICTURE'))?>"><label class="cabinet"><input type="file" class="file" name="pictureUpload" id="pictureUpload" /></label></td></tr></table>'); } else { jQuery('#picture').val(eventPicture); jQuery("#eventPicture").html('<table><tr><td><div class="photoOver section"><div class="photo"><div style="background:url(\'http://<?=$_SERVER['HTTP_HOST'].KRequest::root()?>/media/com_ohanah/attachments/'+eventPicture+'\') center center no-repeat; height: 240px"><img width="249" height="242" src="http://<?=$_SERVER['HTTP_HOST'].KRequest::root()?>/media/com_ohanah/v2/ohanah_images/blank.gif" class="picBorder" /><div class="buttonOverlay"><ul class="photoButtons"><li><a href="javascript:removePicture(\''+eventPicture+'\');" class="deletePhoto">Delete</a></li><li><a href="http://<?=$_SERVER['HTTP_HOST'].KRequest::root()?>/media/com_ohanah/attachments/'+eventPicture+'" target="_blank" class="zoomPhoto">Zoom</a></li></ul></div></div></div></div></td><td><input id="selectPicture" type="button" class="button" value="<?=@text('OHANAH_SELECT_NEW')?>"><label class="cabinet"><input type="file" class="file" name="pictureUpload" id="pictureUpload" /></label></td></tr></table>');And here is the code for the existing photos that are already uploaded.. which i have a text box showing for, but cant seem to get the desc to show or even better be able to edit and save it. function createPhotos() { jQuery( "#eventPhotos" ).html(''); var eventPhotos = '<table><tr>'; var i = 0; jQuery.each(photos, function(key, value) { eventPhotos +='<td>'; eventPhotos += '<div class="photoOver section" id="photo_container_'+i+'"><div class="photo"><div style="background:url(\'http://<?=$_SERVER['HTTP_HOST'].KRequest::root()?>/media/com_ohanah/attachments/'+value+'\') center center no-repeat"><img width="110" height="113" src="http://<?=$_SERVER['HTTP_HOST'].KRequest::root()?>/media/com_ohanah/v2/ohanah_images/blank.gif" class="picBorder2" /><div class="buttonOverlay"><ul class="photoButtons"><li><a href="javascript:removePhoto(\''+value+'\', '+i+');" class="deletePhoto">Delete</a></li><li><a href="http://<?=$_SERVER['HTTP_HOST'].KRequest::root()?>/media/com_ohanah/attachments/'+value+'" target="_blank" class="zoomPhoto">Zoom</a></li></ul></div></div></div></div><br/><input type="text" id="img_description_'+i+'" name="img_description" style="width:100px; margin-top:7px" placeholder="Description">'; if (((key+1)%3)==0) { eventPhotos +='</td></tr><tr>'; } else { eventPhotos +='</td>'; } i++; }); if(photos=="") { eventPhotos += ''; } // modifications var id = getParameterByName('id'); //alert(id); if(id!= '') eventPhotos +='<td><input type="button" class="button" value="<?=addslashes(@text('OHANAH_ADD_PHOTOS'));?>"><label class="cabinet"><input type="file" class="file" name="photoUpload" id="photoUpload" /></label></td>' else eventPhotos +='<td><input type="button" class="button" value="<?=addslashes(@text('OHANAH_ADD_PHOTOS'));?>"><label class="cabinet"><input type="file" class="file" name="photoUpload" id="photoUpload"/></label></td>' if(((photos.length)%3)==1) { eventPhotos +='<td><img width="104" height="106" src="http://<?=$_SERVER['HTTP_HOST'].KRequest::root()?>/media/com_ohanah/v2/ohanah_images/blank.gif" /></td>'; } eventPhotos +='</tr></table>'; jQuery( "#eventPhotos" ).append(eventPhotos); createPhotoToolbars(); }Maybe I am in over my head not sure yet, and maybe I will have to pay someone to finish this, but figured I would atleast give it a try first, I have the database edited to hold the values, which I have added manually. And they are displaying on the website correctly. Just having issues with the admin area. Help!! Thanks in advance. Attached Files images.php 8.15KB 1 downloads Basically I need to select some rows from my database that have been posted in the last 24 hours. So since my date is stored from the values of the time() function I want to do a query to get the results only greater than a certain time code. So if I lets say have this value: 1321184384, what can I subtract to go back 24 hours? Ok I have the following as part of a login script which is supposed to set a cookie upon successful login [php] if (mysql_num_rows($LoginResult) > 0) { $UserID = mysql_result($LoginResult, 0, 'user_id'); $Id = uniqid(); $IdRes = mysql_query("UPDATE ".MEMBER_LOGIN_TABLE." SET `unique_id`={$Id} WHERE user_id='{$UserID}", $db); setcookie('RAYTH_MEMBER_ID', $Id, time()+2592000); Echo "Logged In. Click <a href='index.php?act=idx'>Here</a> to Continue.<br>Note: If you click continue and you are not logged in please ensure cookies are enabled!"; } [/cookie] However when I log in I get: Code: [Select] Warning: Cannot modify header information - headers already sent by (output started at /home/rayth/public_html/style.php:1) in /home/rayth/public_html/login.php on line 38 Logged In. Click Here to Continue. Note: If you click continue and you are not logged in please ensure cookies are enabled! Line 38 is the setcookie() line. Can someone shed light on where I am going wrong here? Hello, The below code works on my home machine.. but not on my Linux machine, I am unable to figure out the problem, please help Code: [Select] require_once("dbconnection.php"); function coun_list() { $rs=mysql_query("select name from timezones") or die(mysql_error()); while($row=mysql_fetch_row($rs)) { $tzone=$row[0]; if($tzone=='Asia/Calcutta') $tzone='Asia/Kolkata'; try { $tz = new DateTimeZone("$tzone"); $lt=$tz->getLocation(); $lat=$lt['latitude']; $lon=$lt['longitude']; echo "$tzone"; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } } } coun_list(); I get the below error on my Linux machine, Code: [Select] Caught exception: DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone () Please help me to figure out the issue.. Hi ,
I try to change a PHP code for a booking program without succes. Now the time set is from 00.00 - 24.00hours but it must be fixed on 15.00H ( dropoff) and 11.00H (pick-up). Can someone help me please ?
Big thanks in advance !
$pickhdeftime = !empty($places[$indvrcplace]['defaulttime']) ? ((int)$places[$indvrcplace]['defaulttime'] / 3600) : ''; I have the following session timeout code which should redirect users of a website to a page (session_expired.php) which prints out a message telling the user that his session has expired. I include this code at the top of every page in the website, that requires user authentication. Code: [Select] <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) { // last request was more than 30 minates ago session_destroy(); // destroy session data in storage session_unset(); // unset $_SESSION variable for the runtime header("location: session_expired.php"); } $_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp ?> The session_expired.php page which I will include below, has a login link, which takes the user to a login page (access_denied.php) Code: [Select] <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //Set the page title before the header file $title = 'Session Expired'; require ('header.php'); //need the header ?> <div id="content" class=""> <div id="left_content" class=""> </div> <!--closes left content--> <div id="right_content" class=""> <div id= "right_content_inner_border"> <h5 style ="position:relative;left:660px;top:1px;"> <a style="text-decoration:none" href="access_denied.php">[Login]</a> </h5> <h3 style ="position:relative;left:110px;top:100px; font-color:blue;"> You Session Expired Due to Inactivity! </h3> </div> <!--closes right content inner border--> </div> <!--closes right content--> </div> <!--closes content--> <?php require ('footer.php'); //need the footer ?> Now here lies the problem. When i set the session timeout to say 60 seconds to test the code, everything seems to work perfectly. The authenticated page gets redirected to session_expired.php after 1 minute and when the user clicks on the login link, he is taken back to the login page(access_denied.php). However, when I replace the time with 1800 seconds, the page notice that when I leave the page idle for JUST about 5 minutes, it gets redirected NOT even to the expected session_expired.php page but strangely, directly to the login page(access_denied.php). What could be going wrong here? Any hint is appreciated. I'm kind of a beginner in PHP and I'm not sure how complicated is this thing I need to do so I just need a little bit of help. Anyway, I have this clock counter on a few of my pages, counting down to 0 and what I need to do is execute certain code 15 minutes before a counter reaches 0. It's basically the same code but it needs to run every time one of the counters is 15 minutes away from 0. Any simple way for me to achieve this? Thanks! Hey Guys, I am fixing someone else's code, so please bear with me on this one. Basically the site has an application form and once the user has submitted the form, they get an automated email with an induction date, and the date is taken from the admin panel where the admin user puts in the date and time and number of applicants. So basically the if the admin user puts in Date: 23th Sept 2011 Time: 9:30 Number of Applicants: 30, the next 30 successfull applicants will get that date and time. The problem with the code is that now whenever the user fills in the application and their application is successfull, they are getting an induction date of Thursday, 1 January 1970 and no time. I am not sure why this happens if someone could point me in the right direction. Here is the snipet of the code where it prints out the date: Code: [Select] Your Induction date is <?php echo (date("l, j F Y", strtotime($array_result_ind['date'])))." at ".$array_result_ind['hour'];?> The code at the top of the page is: Code: [Select] <?php //include('browser_redirect.php'); //Start session and page session_start(); $induction = isset($_GET['id'])?$_GET['id']:''; $_SESSION['change_ind_date_app_ID'] = $induction; $db_leafletj_jobs = mysql_connect("localhost", "leafletj_jobs", "t10872") or die(mysql_error()); $sel_leafletj_jobs = mysql_select_db("leafletj_jobs") or die(mysql_error()); $query_str = "SELECT applicants.id, applicants.unique_ref, applicants.app_date, applicants.fname, applicants.surname, applicants.ind_date, applicants.ind_ord_no, inductions.date, inductions.hour FROM (applicants JOIN inductions ON (applicants.ind_date = inductions.date)) WHERE applicants.id=".$induction; $result_ind = mysql_query($query_str, $db_leafletj_jobs) or die(mysql_error()); //$count = mysql_num_rows($result_ind); $array_result_ind = mysql_fetch_array($result_ind, MYSQL_BOTH); ?> Also the database for the induction date and time is blank. I haven't designed the application so I am a little lost. I the system was all working a couple of weeks ago but now all of a sudden it prints out that 1970 date with no time. Is this a quick fix? Thanks, Ken I'm working on a project that has a lot of different timezone options, and all I have from the users is their UTC offset. After weeks of doing tweaks, I come to new issues every time I add something, one would think it would be a lot easier to just get the correct time and day :) The latest issue is that when I try to rewrite a date to a better fomat, it disregards the GMT offset. Like this: 4/14/19, 12:00 PM GMT+2 (=$date) becomes ... 14-04-2019 10:00 when using this code: $bp_date_to_format = date_create_from_format('Y-m-d\TH:i:sP', $date); echo date_format($bp_date_to_format, 'd-m-Y H:i'); I figured it would just rewrite the format, keeping the exact time. It isn't. We do have all these sorts of localization functions as well, but because there doesn't seem to be one single standard (each 3rd party API connection we have uses its own default datetime format so it seems). // Remove UTC Text $UTC_offset = str_replace('UTC', '', $timezone); // Get Offset in Minutes if (stripos($UTC_offset, ':') !== false) { // Calculate seconds from offset list($hours, $minutes) = explode(':', $offset); $seconds = $hours * 60 * 60 + $minutes * 60; } else { $seconds = $UTC_offset * 60 * 60; } // Get User timezone name from seconds $timezone = timezone_name_from_abbr('', $seconds, 1); if ($timezone === false) { $timezone = timezone_name_from_abbr('', $seconds, 0); } // Set new TZ return date_default_timezone_set($timezone);
Isn't there any "one way"solution that can be used? It's confusing to say the least.
Cheers. This topic has been moved to Editor Help (Dreamweaver, Zend, etc). http://www.phpfreaks.com/forums/index.php?topic=322054.0 <?php query_posts('meta_key=post_views_count&posts_per_page=3&orderby=meta_value_num& order=DESC'); if (have_posts()) : while (have_posts()) : the_post(); ?> <ul class="rpul"> <li> <div class="class="post-thumb wp-post-image" style=' '> <?php if ( has_post_thumbnail() ) : ?> <?php the_post_thumbnail('thumbnail') ?> <?php endif ?> </div><div class='cat-post-text'> <h1> <a href="<?php the_permalink(); ?>"><?php the_title(); ?>
Hello, I am building an online game(users make a character and move on a map and so on...)
All user data is stored in a mySQL database and I want the users to interact in real-time, but there can be a 1-3 second delay between the communication, but not exceed 3 seconds even if 500 players are playing at the same time.
But for the purpose of the question let's say the users can only chat between one another, if I'll have a solution for that then I can use the same method for more parts of the game.
I can't use websockets because my webhost doesn't support it( I don't want to use pusher.com).
I know I can make real-time apps with ajax long polling, but I think that with 500 players playing at the same time it's not the best solution.
So, finally:
How can I make user interaction as close as possible to a real-time game?
(Without too much load on the hosting server)
(I am sorry if some of my terms are not correct - I am just getting back to coding after a long time...)
Edited by Mythion, 17 August 2014 - 02:34 AM. Hello I am trying to only display results within the time period last sunday too next sunday. my code: Code: [Select] <?php $today = date('Y-m-d H:i:s'); $time = strtotime($today); $last_sunday = strtotime('last sunday', $time); $next_sunday = strtotime('next sunday', $time); $format = 'Y-m-d H:i:s'; $last_sunday = date($format, $last_sunday); $next_sunday = date($format, $next_sunday); ?> <?php $sql_totalsurfs = ("SELECT vtp_members.id, vtp_members.name, vtp_members.teamleader, vtp_tracking.Timber, vtp_tracking.Stone, vtp_tracking.Marble, teams.team_name, count(vtp_tracking.id) surfs FROM vtp_members, vtp_tracking, teams WHERE vtp_members.team_id=".$_GET['t']." AND vtp_tracking.credit_members_id=vtp_members.id AND vtp_tracking.action_date>'$last_sunday' AND vtp_tracking.action_date<'$next_sunday' GROUP BY vtp_members.id ORDER BY surfs DESC LIMIT 0, 10"); $rstotalsurfs = mysql_query($sql_totalsurfs); $numrows = mysql_num_rows($rstotalsurfs); ....... Is there and error somwhere in the code? PHP date and time function is not showing correct time on my local system I have the following php code date_default_timezone_set("Africa/Lagos"); $date = date('d-m-y h:i:s'); echo "Server Time ".$date ."<br>"; echo "The time is " . date("h:i:sa")."<br>"; $current_datetime = date("Y-m-d") . ' ' . date("H:i:s", STRTOTIME(date('h:i:sa'))); echo "Current time1: ".$current_datetime . "<br>";
Output
Server Time 21-05-21 09:55:39
Expected Output
Server Time 21-05-21 10:55:39
Any help would be appreciated. Edited May 21 by Ponel I am trying to simulate an ad expiration and carry out an action if the ad is expired. And I cannot get the if/else to work properly... I've tried many variations and I cannot see what I am doing wrong here. Any tips please 3 hours and counting of no solution! $ad_start = time()-14 . "<br />"; // 14 days from today in the past (negative) echo $ad_start; $current_time = time() . "<br />"; // current epoch time echo $current_time; $days_past = $ad_start - $current_time; // days past echo "<br />$days_past days have past since the ad started!<br />"; if($days_past <= 14) { echo "<br />Ad is less than 14 days. Not expired."; } else { echo "<br />Ad is over 14 days. Expired."; } |