PHP - Question About How To Track And Display Time Correctly
I'm interested to know how other people keep track of time and also how they display time correctly back to the users. I'm using a third party API that I can tie into that actually gives me the userID of a user, their full name and the timezone for that user. After checking a few users data, this is an example data of what I'm working with.
userID: 234213412 first_name: foo last_name: bar timezone: -6 Basically when a user visits my web app, I create a new account for them and store the above data. Currently, I'm just fetching the result from time() and converting it into MySQL DateTime format and storing that into my database. Code: [Select] //get the current time as an integer $php_timestamp = time(); //formats the time according to MySQL DateTime type $this->mysql_formatted_time = date('Y-m-d H:i:s', $php_timestamp); I would think the current way that I'm doing this is not very good because there is a possibility that I could introduce load balancing servers into the mix and they might not be located in the same region. Also, I would have no idea how to factor the time and modify it according to the timezone value.(in my above example, -6) Can anyone help me decide what method I should use to keep all of my servers timestamps in sync and how to display the time to the end user so that it looks correct to them? Similar TutorialsPHP Websockets Rate limiter (Thanks to @Kicken for the help) How do I setup let's say... no more than 5 requests per second? Any idea? // anti flood protection if (isset($users[$clientID]['last_session_request'])) { if($users[$clientID]['last_session_request'] > ''.microtime(true).'' - 1){ // users will be redirected to this page if it makes requests faster than 1 seconds echo "Limit Reached... Simmer down!"; wsClose($clientID); }else{ } $users[$clientID]['last_session_request'] = microtime(true); } Edited by Monkuar, 20 December 2014 - 03:28 PM. hello . i have a comments box on my site that doing some strange things. if i type anything in and press enter it adds more characters. http://www.grosvenorassociates.com/contact.php for example if i type 1 2 3 4 5 6 and press submit, i get 1\r\n2\r\n3\r\n4\r\n5\r\n6 if i type a b c d e f i get a\r\nb\r\nc\r\nd\r\ne\r\nf this is the code im using: Code: [Select] <textarea name="comments" type="text" class="textarea" value="<?PHP echo $comments; ?>"/><?PHP echo nl2br($comments) ?></textarea> i ideas whats doing this and how to fix it ? thanks rick I am able to make the map shift to the direction as intended but I got a few other problems: 1. The player location isn't properly loaded, eventhough it saved to the database successfully (I use locationX and locationY as XY coordinate individually). The X and Y corrdinates shows up on the URL itself like this ".../main.php?x=#&y=#". But if I remove them and then hit enter again the it will reset the position back to the original location of the map. 2. The player tile does not appears in center of the map tiles. Here is the page I uploaded my PHP script: http://student18.gamfe.com.hk/facebook/main.php Here is the map portion of the code: Code: [Select] <?php $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection'); mysql_query("SET NAMES 'utf-8'"); mysql_select_db($dbname) or die(mysql_error()); $query = "SELECT * FROM game_user WHERE game_id = '00001'"; $result = mysql_query($query) or die(mysql_error()); if ((!empty($_GET["x"])) && (!empty($_GET["y"]))) { $updateString = "UPDATE game_user SET locationX=".$_GET["x"].", locationY=" .$_GET["y"]. " WHERE game_id = '00001'"; mysql_query($updateString); } else { $x = 2; $y = 2; } ?> ... // Phrasing map tiles and player tile code <?php $file = file_get_contents('./images/maps/33/map.txt', true); $entries = explode("\n", $file); for($i=$x-2;$i<=$x+2;$i++){ $data = explode(",", $entries[$i]); for($j=$y-2;$j<=$y+2;$j++){ echo "<td align=\"center\" background=\"images/maps/33/33_"; echo $data[$j]; echo ".gif\" width=\"65\" height=\"65\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"65\" height=\"65\"> <tbody><tr> <td> <center>"; while($rows = mysql_fetch_array($result)) { if(($rows['locationX'] == $_GET["x"]) && ($rows['locationY'] == $_GET["y"])) { echo "<img src=\"../images/player_tile.gif\" title=\"You are here\">"; } } echo "</center> </td> </tr></tbody> </table> </td>"; } echo "</tr><tr>"; } ?> I have a problem with the three special characters in the Danish language: æ, ø and å. I have created a database with a simple table manually within phpMyAdmin, and I have added contents, which is text with the letters mentioned. Everythings looks correct in here. But when I get the content of the database written out via a php document, these three letters are replaced with a box sign. In phpMyAdmin I chose "utf8_danish_ci" as collation. And here is the code of the php document writing out the content of the database table, named "lille_tabel", with the password written with stars.
<!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> <?php $server = "localhost"; $brugernavn = "root"; $kodeord = "************"; $db = "lille"; mysql_connect($server,$brugernavn,$kodeord) or die(mysql_error()); echo "Forbundet til MySQL server<br/>"; mysql_select_db($db) or die(mysql_error()); echo "Forbundet til Databasen<br/>"; $data = mysql_query("SELECT * FROM lilletabel") or die(mysql_error()); while ($info = mysql_fetch_array($data)) { echo "ID: ".$info['id']."<br/>"; echo "Navn: ".$info['navn']."<br/>"; echo "Tekst: ".$info['tekst']."<br/>"."<br/>"; } ?> </body> </html>By the way: I use Dreamweaver. I hope someone have suggestions to pinpoint the problem ... Regards, Erik Hey guys, How would I go about subtracting Today from a previous day to find the difference? For example, I want to subtract TODAY from a previous date in my database, to determine if the difference is greater than 1 day. Any ideas? I tried doing the subraction in TIMESTAMPS, but when I convert the date back to Y-m-d H:i:s, I got some weird year and time. I am trying to display "open" / "closed" depending on the time of day. I tried to write my own script but it doesn't seem to be working. Does anyone know of some boxed script I can use? Here is what I have... function open(){ $AMPM = date('A', time()); if ($AMPM == "PM"){ connect(); $day = date('l'); $sqlcurrent = "select * from hours where day = '$day' and closed ='1'"; $currently = mysql_query($sqlcurrent) or die(mysql_error()); $checkDay = mysql_num_rows($currently); if ($checkDay == "1"){ while($getID = mysql_fetch_assoc($currently)){ $convertopen = strtotime($getID['open']); $convertclose = strtotime($getID['close']); $displayTimeH = date('H', time()); $displayTimeM = date('i', time()); $displayTimeAMPM = date('A', time()); $opentime = explode(":", $getID['open']); $openhour=$opentime[0]; $openminute=$opentime[1]; $closetime = explode(":", $getID['close']); $closehour=$closetime[0]; $closeminute=$closetime[1]; //echo "$closehour$closeminute<br />"; //echo "$displayTimeH$displayTimeM<br />"; if (($openhour <= $displayTimeH && $openminute <= $displayTimeM) && ($closehour >= $displayTimeH && $closeminute >= $displayTimeM)){ echo "We're Open ... Come On In!"; }else{ echo "Hours of Service"; } } }else{ echo "Hours of Service"; free($currently); } }else{ echo "Hours of Service"; } } // close function I know it's brutal but it's all I could come up with... At the moment I have: $month_end_date[$surgeryinvoicescount]=$i[0]; = 2011-04-13 I would like $month_end_date[$surgeryinvoicescount]=$i[0]; = 13/04/2011 I have tried the following but didn't work?!: $month_end_date = date('d/m/Y',strtotime($month_end_date)); $month_end_date[$surgeryinvoicescount]=$i[0]; Hey all. I have a query that selects data from a datbase based on a criteria. Easy enough. But now I am growing and the amount displaying is too much. How can you, via php, have a queries result be displayed only so many at a time and auto create links that show the rest? Like if query returns 82 results, I want it to display 25 immediately and create 3 links at the bottom. The next link would show 26-50. The next 51-75. And the final 76-82. etc Example: Code: [Select] $result = mysql_query("SELECT * FROM pay"); $num_rows = mysql_num_rows($result); while($row = mysql_fetch_array($result)) { echo $row['first_name']; echo $row['last_name']; echo $row['item_name']; echo $row['option_selection1']; echo $row['payment_date']; echo $row['stat']; } This is simple. But what happens when the results are 125? I want to limit it to displaying 25 at a time. Is the only way to manually create seperate pages and have each one show 1-25, then 26-50, etc? Or is there a way to have the script do it, itself? Any tutorials out there on this specifically? Hopefully I am making sense. Thanks! Hello Everyone, I wanted to know how to Display records from a Table one by one at difference time intervals. Kindly suggest This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=314226.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=321950.0 I have a datetime table in my db. my time stamps look like this 2011-09-28 16:34:03 My question is this If I have a time in of 2011-09-28 10:34:03 and a time out of 2011-09-28 18:04:03 how can I figure out the hours worked? Any help is appreciated. Does time zone change have to occur in an INI file, or can I place it as a value. I've tried using default_time_zone ('America/New York') but had no success with it, even to just ECHO a statement that says: It is now 3:50PM in New York. I need to create some sort of queuing system for my php application to function properly. I was just going to a simple one with a column named "enqueued" and have a queued table that has id, start_time, stop_time. It's more like an ordered "delayed" queue system.. eh whatever. Anyways, what would be the best way to store and access the times in the database? I'm supposing I can just use a TIMESTAMP and have the default value set to TIMESTAMP for the start_time, how how about stop_time I'm assuming still a TIMESTAMP, but with no default value and it can't be null. But, how would I do the time in php? Like adding an amount to a timestamp.. and is there any special functions I can use to read the results from the mysql timestamp fields? Let's say I wanted to take a timestamp of now and add 40 minutes to it.. how do I do this? Hello everyone, With the recent time change, I found a new problem with my code. I think I have it fixed by utilizing the "date_default_timezone_set()" function, but I have a question. Does this php time/date function automatically account for daylight savings time, is it something that will have to be adjusted in my code? I think I can figure out how to adjust it if it's needed, but I don't want to have to do the work if it is updated automatically. Thanks for any help. After doing some reading im trying to make sure I understand how all this time stuff works with using sql I have a Session created for users that uses $_SESSION['login_time'] = time(); when I echo that it comes up as 1324245123. so the reason it looks like that is because that is what UNIX looks like? So thats why this code doesnt work if ($get1['date'] > strtotime('-1 minutes')) { because the date im getting from $get1 is a sql time stamp and the strtotime is UNIX and they dont match do I understand this right? Hi, I am new to this forum as of now. I have a question which probably has a very straightforward answer but I just can't solve it. I am using mysql and have the following code: while($row=mysqli_fetch_array($result)) { $time1=date("j F Y G: i", $row[1]); echo "<tr><td>$row[email]</td>"; echo "<td>$time1</td>"; echo "<td>$row[comment]</td></tr>"; } It is the first line in the curly brackets that is causing the problem. If I replace $row[1] with $time I get today's date/time. But I need the date/time from what has been input so that won't work. Can anyone explain to me what is wrong with my code please? It gives the following error message: Notice: A non well formed numeric value encountered in C:\xampp\htdocs Thanks very much It seems like this is a question that may be on here already, but I couldn't find it with a search, so I apologize. I am given a string that represents a datetime, and it is always in this format: HH:mm:ss MMM DD, YYYY PDT. I just want to turn that into a proper format for mysql (Y-m-d H:i:s), but I'm not exactly sure how to go about that. (I could do this in C# rather quickly!) Probably a simple question, I hope someone can help! Thanks. I'm trying to convert the following time stamp: 12:03PM to military time 13:03. I'm using the following code, but it's just outputing 12:03: $sampledate=("2010-11-08, 12:03PM CST"); $xplodeDateStamp = explode(", ", $sampledate); $xplodeDate = $xplodeDateStamp[0]; $xplodeTime = $xplodeDateStamp[1]; echo "Date: " . $xplodeDate . "<br>"; echo "Time: " . $xplodeTime . "<br>"; echo "Military Time: " . date("H:i",strtotime("$xplodeTime")); Hi,
i am a student for a school.
we have in each class a book that lists the shool year. Teachers use it to make notes in it and mark people that are not present.
i want to bring that whole process online making a website out of it.
Teachers can log in and see the yearbook. Days view, Week view, Month view. Mark people that have been missing on a specific day. List all the people that have been missing during a school week.
How would i present the Calender? Tables?
I have the some knowledge in mysql, php and joomla.
How would i go about getting startet? Do i need to have a Framework?
All ideas would be greatly appreciated.
Thank you
|