PHP - How To Check If 10 Minutes Passed Since Last Bump?
I have a forum script I made that has thread bumping for the thread creator only. I am trying to limit the amout of time the creator can bump to be every 10 minutes.
Here's my code. list($title, $creator, $locked, $hidden, $moved, $lastbump) = mysql_fetch_row(mysql_query('SELECT title, creator, locked, hidden, moved, lastbump FROM forum_threads WHERE id="'.$_GET['threadid'].'"')); if(($locked == 1 || $hidden == 1 || $moved == 1) && !$_SESSION['rights'] == 2){ header("location: thread.ws?id=".$_GET['threadid']."&page=".$_GET['page'].""); } else { if($creator == $_SESSION['username']){ mysql_query("UPDATE forum_threads SET lastbump = NOW() WHERE id='".$_GET['threadid']."'"); } else { header("location: thread.ws?id=".$_GET['threadid']."&page=".$_GET['page'].""); } } Similar TutorialsHi all, How can I check in PHP if this date has already passed in the following format: 2012-12-12 To get current date and time I use: $date = date("d-M-Y h:i:s"); But how can I get date and time which was before 5 minutes. I'm trying to add some minutes ($interval) to any given time, but my results aren't as expected... Code: [Select] <?php $year="2012"; $opentime="09"; $interval="10"; $thedate = "$year:01:01 $opentime:00:00"; $startdate = strtotime($thedate); $date = date("Y-m-d",$startdate); $time = date("g:i a",$startdate); $newtime = strtotime("+$interval", $time); $nexttime = date("g:i a",$newtime); echo $date; echo "<br>"; echo $time; echo "<br>"; echo $nexttime; is returning: 2012-01-01 9:00 am 7:10 pm I was expecting the last to be 9:10 am. Can someone point me in the right direction? Thanks. I have a database with Users as a table. It has the normal stuff, id, username, password, and I have anther in it called lastactive. It is int(11) , and I am wondering how I would make a sql query select the users in the database 'users' and see who has been active in the past 15 mins. By the way, the lastactive time gets updated by the function time() Here is my code: <?php $online = mysql_query("SELECT * from users WHERE (TIMESTAMPDIFF(MINUTE, `lastactive`, NOW()) < 15) ORDER by lastactive DESC") or die (mysql_error()); while($online = mysql_fetch_assoc($online)) { echo '<a style="color:#F0CD87;" href="profile?id='.$online['user_id'].'">'; echo ucFirst($online['username']); echo '</a>, '; } ?> Here is how the last active gets updated. <?php if(isset($_SESSION['logged'])) { mysql_query("UPDATE `users` SET `lastactive`='" . time() . "' WHERE `username`='" . $_SESSION['username'] . "'"); } ?> Again its not showing the users that have been on since 15 minutes ago, even tho it updates the users last active on every page since its in the footer.php part. which is on every page. Thanks for the upcoming help. so i have a mysql column with a datetime and i was wondering how i could make it echo the time in "X minutes ago" or "X hours ago" and also, when its more then 24 hours old, delete the entire entry I've created a demo page for my CMS, and I want to delete itself and make a fresh content install. I got the delete part figured out, but what about uploading fresh content files? (only a few text files). Here's the delete part: Code: [Select] <?php $expiretime=720; // minutes (in how many minutes it deletes the files) $tmpFolder="tmp/"; // where to delete the files - be careful with this. $fileTypes="*.*"; foreach (glob($tmpFolder . $fileTypes) as $Filename) { $FileCreationTime = filectime($Filename); $FileAge = time() - $FileCreationTime; if ($FileAge > ($expiretime * 60)){ //deleting files: unlink($Filename); } } ?> hello, if i have the following, how would i display it? Code: [Select] function minutes_round ($hour = "$signintime", $minutes = '5', $format = "H:i") { $seconds = strtotime($hour); $rounded = round($seconds / ($minutes * 60)) * ($minutes * 60); return date($format, $rounded); } Hey guys only thing i can find online is examples of showing how much time is left until a predetermind time. but what I need is how many minutes are left until the next hour hits anyone have any ideas on this? Im wanting to do it in UNIX time Unfortunately I do not know how to go about doing this in php any simple examples of time and date will be great. So what I am trying to do is, display to minutes until the next half hour as well as the seconds until the next minute. Eg. Code: [Select] <?php echo $minutes; ?>:<?php echo $seconds; ?> Any help using the time and or date functions in this case will be great. Thank you for your stupendous help. Brian This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=352669.0 I wrote a function that grabs the elapsed time of a recently uploaded video. However, the time does not seem to increment. For example, if I upload a video, the time will display as '1 second'. However, if I continuously refresh the page, the time does not increment or increase. Any way to fix this? I figured I'd have to put it in some kind of loop (I do call the function in another class).
function getElapsedTime($time) { $time = time() - $time; // get time since video upload date $time = ($time < 1) ? 1 : $time; $tokens = array( 31536000 => 'year', 2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second' ); foreach ($tokens as $unit => $text) { if ($time < $unit) continue; $numberOfUnits = floor($time / $unit); return $numberOfUnits . ' ' . $text . (($numberOfUnits > 1) ? 's' : ''); } }
Other than if statement, is there a way to change a duration give in seconds (e.g. 5746 seconds) to the standard format of x hours and y minutes and z seconds? Hello! I want to be able to make a code that tells me how many saturdays have passed till today. I've tried a couple of things but nothing. Any help?! Thanks! Hi I am trying to get all variables passed in a url string and wondered how would i do it? I dont know what they are yet and i need to set key as value. Any help? Hi I use Dreamweaver to do a lot of my work on a php/mysql database. I have two tables - applications and contacts and they are linked by the id appid. When I view a page with all of the application and contact details the url contains the appid as a number at the end (eg .../Summary.php?appid=639) When I want to edit one of the contacts I go to the edit page but this is identified by a contact id so that url looks like: ../EditContact.php?contactid=32 When I update the contact's details I would like to return to the summary page but can't as the url gets muddled between the two different ids so I end up at a page with no info on it. How can I get round this? I'm sorry my explanation isn't very clear but any help is much appreciated.
Hi All, I've been trying to access xml data from an API feed, but it needs a Variable to be passed to an include file without a form. the include is at the header of the page. in the code below, i'm trying to retrieve the variable $project_add from the $xml_2 feed. $proj_add_ID comes from another feed and is being passed ok. foreach ($projects_1 as $proj_1) { $job_no =$proj_1['job_no']; $job_name =$proj_1['job_name']; $job_status =$proj_1['job_status']; $job_staff =$proj_1['job_staff']; $job_due =$proj_1['job_due']; $clr_1 = $colors_1[$job_status]; if ($err_2) { echo "cURL Error #:" . $err_2; } else { $_POST['job_id']= $job_no; $xml_2=simplexml_load_string($response_2) or die("Error: Cannot create object"); $proj_add = $xml_2->xpath("CustomFields/CustomField[ID ='$proj_add_ID']"); foreach($proj_add as $item_2) { $project_add = "$item_2->Text"; } echo "<div class='row no-gutters'>"; echo "<div class='col-sm bg-white border rounded'><a href='managejob.php?job_id=$job_no' class='text-left ml-1'><strong>$job_no</strong></a></div>"; echo "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'>$job_name</p></div>"; echo "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'></p>$project_add</div>"; echo "<div class='col-sm-2 bg-white border rounded'>" . state_dropdown_1($job_no, $job_status, $clr_1) . "</div>"; echo "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'>$job_staff</p></div>"; echo "<div class='col-sm-2 bg-white border rounded'><form action='CALL_API_PUTTaskDate.php' method='POST'>" . "<input type='hidden' name='task_ID' value ='". $jdata['task_ID'] ."'>" . "<input type='hidden' name='est_min' value ='". $jdata['est_min'] ."'>" . "<input class ='form-control bg-white text-dark font-weight-bold' type='date' name='start_date' value='" . date('Y-m-d', strtotime( $jdata['display_date_1'] )) . "' onchange='this.form.submit()'>" . "</form></div>"; echo "<div class='col-sm bg-white border rounded'><p class='text-left ml-1 mt-1'><strong>" . date('d/m/Y', strtotime( $jdata['display_date'])) . "</strong></p></div></div>"; } The include file is like this / collect Custom Felds if ($_SERVER["REQUEST_METHOD"] == "POST") { // collect value of status input field $job_no = $_REQUEST['job_id']; } if (isset($_POST['job_id'])) { $job_no = $_POST['job_id']; } if (isset($_GET['job_id'])) { $job_no = $_GET['job_id']; } $curl_2 = curl_init(); curl_setopt_array($curl_2, array( CURLOPT_URL => "https://api.xxx.com/job.api/get/$job_no/customfield?apiKey=xxx&accountKey=xxx", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "Accept: */*", "Accept-Encoding: gzip, deflate", "Cache-Control: no-cache", "Connection: keep-alive", "Host: api.xxx.com", "Postman-Token: xxx", "User-Agent: PostmanRuntime/7.17.1", "cache-control: no-cache" ), )); $response_2 = curl_exec($curl_2); $err_2 = curl_error($curl_2); curl_close($curl_2); The problem is the variable $job_no isn't getting passed to CURLOPT_URL so it's not retrieving the data required. i need to be able to retrieve this data without submitting a form as it's in a foreach loop and the Id is specific to each iteration. is there a way to do this? I have been able to achieve this by putting the include within the div tags that it will be displayed but it just slows down everything too much and hangs. Any help will be much appreciated. Kind regards, Michael Bennington. I am trying to pass a php variable to javascript but it's not working. This is the "sketch" of my code. <?php $url="asset/go/"; ?>
<!DOCTYPE html> <html> <head> <title>Page Title</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> </head> <body> <script> var user="mayor"; var url ='<?php echo json_encode($url); ?>'; if(user=="mayor"){ alert(url); } </script> </body> </html> As it is now, it comes with the output below: <?php echo json_encode($url); ?> If I remove the quotation around the php in d jQuery, it throws an error in syntax. Also both codes are located in the same file named test.php Thanks in advance. Edited April 18 by Abel1416Good day freaks. I am pulling my hair out trying to figure this out. I am trying to pass patterns for preg_replace through $_GET and then apply them. The object is to highlight certain words in a chunk of text. Say I want to highlight bounded cases of 'foo' in the text. So here's what I'm doing: Code: [Select] $string = urldecode($_GET['highlight1']); // $string contains \\bfoo\\b $search = preg_replace('/\\\\b/','b',$string); // $search contains \bfoo\b as I want it to $replace = preg_replace('/\\\\b/','',$string); // $replace contains \foo\ >:-( $pattern = '/'.$search.'/i'; $text = preg_replace($pattern,'<span style="background-color:yellow;">'.$replace.'</span>',$text); The problem is that no matter what I try for the pattern for $replace, it winds up with backslashes around foo. How do I get rid of these? (I should say that I discovered the pattern/replace for the $search string by experimentation and I don't understand why the pattern doesn't pick off all the backslashes in that case--but at least it does what I want). TIA Steve In my main script I set $errorArray with values when required survey questions go unanswered. The ne code that checks for missing required values is working perfectly, and right before I pass $errorArray to a function which rebuilds the survey questions - this time with the error messages - I do a var_dump($errorArray) and that array has errors in it as expected. But while my function that re-builds the survey questions gets called and does indeed re-build the survey questions, the $errorArray isn't getting pased for some strange reason? (I'm not sure if i have ever passed an array to a function before.) In my function I have... function generateSurveyItem($dbc, $questionNo, $questionID, $surveyResponseArray=NULL, $errorArray=NULL){ }
When I var_dump($errorArray) at the top of the function, and submit a blank form, I end up with a blank page and a file path to my PHP script ending with... /public_html/utilities/function.php:3010:null
Questions: 1.) What is happening?
2.) I thought =NULL in the parameter list just meant that the argument is "optional"?
3.) I am able to successfully pass $surveyResponseArray to this function, so what is up with $errorArray?
P.S. When I run things, and submit an empty form - thus no "required" fields get completed - the survey gets re-displays, and any values chosen are "sticky", but my error messages should also be displayed to let the user know what is mising, and that is the part that isn't working? This has to be something silly stupid to fix... Edited February 16 by SaranacLake Hi, I want to update a row when 30sec are passed on a page. If not nothing happens(not updating row). Example: You go to example.php>> 30sec pass, update row>> 30sec not over, no update. it does not necessarily have to be second it can be minutes or hours. Who can help me? Hope its clear enough, Thanks. |