I'm working on User Functions for the CMS I'm working on and I have users updated on each page load Using
if(User("online") == true) {
LastOnlineUpdate($_SESSION['key']['userid']);
}
(Yes User Online Works, That's my function to check online users)
And now my times are updated correctly hooking into the LastOnlineUpdate function then running my class function
public function SessionUpdate($arg) {
$query = <<<SQL
UPDATE {$this->tprefix}online
SET remote = :remote, timestamp = :timestamp
WHERE userid = :arg
SQL;
$resource = $this->db->db->prepare( $query );
$resource->execute( array(
':remote' => $_SERVER['REMOTE_ADDR'],
':timestamp' => time(),
':arg' => $arg,
));
}
Now whenever I go through my pages it updates the user by having the first code within my preloaded file, now I've hit my roadblock though with something I've never done and that's to take the time that's been inserted into my table, select it if the time is less than five minutes and utilize it for my online users section
public function OnlineUsers() {
$query = <<<SQL
SELECT userid
FROM {$this->tprefix}online
WHERE timestamp > time(5Minutes)
SQL;
$resource = $this->db->db->prepare( $query );
$resource->execute();
$this->onlinecount = $resource->rowCount();
if($resource->rowCount() == 0 ) {
$this->onlineusers = "No User's Online";
}
else
{
foreach($resource as $row) {
self::ConvertIDToName("displayname"); //Can be display, user, first or whatever else for the argument, The onlineusers variable is then set based off that query
}
}
}
$minutes = 5;
$date = gmdate('Y-m-d H:i:s'); // http://php.net/manual/en/function.gmdate.php
$date_plus_minutes = gmdate('Y-m-d H:i:s', ( time() + $minutes * 60 ) );
$date_minus_minutes = gmdate('Y-m-d H:i:s', ( time() - $minutes * 60 ) );
Related
I am using CodeIgniter. I am working on the small project which is a Batch list. Now If an admin wants to create the batch list then should enter the start date and end date and start time and end time then it will check in the database that batch is running on the same date and time? If yes then it will display the message if not then it will create a new batch list.
If the date is the same the time should be different.
Now My logic is,
I am comparing the first new_start_date with exist_start_date and exist_end_date if date found in between then it will check the time.
It's working till date compare. Even it's checking the time but from there how to exit the process and call the JSON? because from there my JSON not working.
I added "echo "time not match";" from there I am not able to call the JSON I am getting the output on my network tab.
I am getitng the output
enter 1enter 2{"error":true,"msg":"Batch Created"}time not match
Would you help me out in this?
$id = $this->input->post('venue_id');
$venue_id = implode(',',$id);
$activity_list_id = $this->input->post('activity_name');
$new_batch_start_date = date('Y-m-d',strtotime($this->input->post('start_date')));
$new_batch_end_date = date('Y-m-d',strtotime($this->input->post('end_date')));
$new_batch_start_time = $this->input->post('start_time');
$new_batch_end_time = $this->input->post('end_time');
$days = implode(',',$this->input->post('days'));
//print_r($days);
if($new_batch_start_date >= $new_batch_end_date)
{
$response['error'] = false;
$response['msg'] = "End Date Should be Greater than Start Date";
echo json_encode($response);
return false;
}
//convert in Time Format
$new_batch_start_time = strtotime($new_batch_start_time);
$new_batch_end_time = strtotime($new_batch_end_time);
$venue = $this->input->post('name');
$data = array(
'activity_list_id' => $this->input->post('activity_name'),
'batch_venue_id' => $venue_id,
'batch_name' => $this->input->post('batch_name'),
'start_date' => date('Y-m-d',strtotime($this->input->post('start_date'))),
'end_date' => date('Y-m-d',strtotime($this->input->post('end_date'))),
'start_time' => $this->input->post('start_time'),
'end_time' => $this->input->post('end_time'),
'total_capacity' => $this->input->post('total_capecity'),
'batch_status' => 1,
'created_by' => trim($this->session->userdata['login_data']['user_id']),
'created_date' => date('d-m-Y h:i:s A'),
'batch_days' => $days
);
$get_batch_details = $this->Batch_model->fetchBatches();
if(!empty($get_batch_details))
{
foreach ($get_batch_details as $rows)
{
$exist_batch_start_date = $rows->start_date;
$exist_batch_end_date = $rows->end_date;
$batch_time1 = strtotime($rows->start_time);
$batch_time2 = strtotime($rows->end_time);
$batch_venue_id = explode(',',$rows->batch_venue_id);
$common_venue_id = array_intersect($id,$batch_venue_id);
//print_r($common_venue_id);
if($common_venue_id)
{
echo "enter 1";
//if new batch start date between existing batch start date
if($exist_batch_start_date <= $new_batch_start_date && $exist_batch_end_date >= $new_batch_start_date ){
echo "enter 2";
if($batch_time1 <= $new_batch_start_time && $batch_time2 > $new_batch_start_time){
$msg = "Other Batch Alredy Running On from Date $batch_start_date to $exist_batch_end_date on Time : $batch_time1 to $batch_time2.
Please Change Time Slot or Start And End Date";
$response['error'] = false;
$response['msg'] = $msg;
echo json_encode($response);
exit;
}
else{
$result = $this->Batch_model->createBatch($data);
echo "time not match";
print_r($result);
}
break;
}
//if date is different
else
{
$result = $this->Batch_model->createBatch($data);
}
}else
{
$result = $this->Batch_model->createBatch($data);
}
}
}
//first time creating batch
else
{
$result = $this->Batch_model->createBatch($data);
}
Mobel
function createBatch($data){
if($this->db->insert('batch_list',$data))
{
$response['error'] = true;
$response['msg'] = "Batch Created";
echo json_encode($response);
}
else
{
$response['error'] = true;
$response['msg'] = "Failed to Create Batch";
echo json_encode($response);
}
}
function fetchBatches()
{
$result = $this->db->where(['batch_list.batch_status'=>1,'activity_list.act_status'=>1])
->from('batch_list')
->join('activity_list','activity_list.activity_id = batch_list.activity_list_id')
->get()
->result();
return $result;
}
Ajax
success: function(response){
var data = JSON.parse(response);
if (data.error == true){
swal({
title: "Success",
text: data.msg ,
type: "success"
}).then(function(){
location.reload();
}
);
} else {
swal({
title: "Warning",
text: data.msg ,
type: "warning"
});
}
}
Would you help me out in this issue?
your entire approach is a bit messy because you find yourself in a ton of redundant code fragments and nobody is able to understand what exactly you want - i gv you some hints here including an example based on your code
Use Exceptions - it's perfect for your case - if something goes wrong - stop it
Try to filter your need to an extent of one single task und try to solve it - and only after that go to the next task
Always - remember always - think about one term - if you find repeatedly the same code in your application - you know something is wrong - and you should refactor it - don't be ashamed about redundancies - they do always happen - but if you find them, you must refactor those code snippets
Now to your example
What are your tasks here ?
you can try to ask your database if a batch is already running - you dont need to iterate over the entire table entries
Compare both input Dates from Administrator - if start date is in the future of end date, instantely stop the application
your intersection isn't really clear to me what you want to achieve here - but i'm really convinced you can ask the database here too (catchword: find_in_set)
Based on that information we can start to develop things now ;) (if i don't have everything just complete the list above and try to implement your task)
Controller:
try
{
$id = $this->input->post('venue_id');
$venue_id = implode(',',$id);
$activity_list_id = $this->input->post('activity_name');
$new_batch_start_date = date('Y-m-d',strtotime($this->input->post('start_date')));
$new_batch_end_date = date('Y-m-d',strtotime($this->input->post('end_date')));
$new_batch_start_time = $this->input->post('start_time');
$new_batch_end_time = $this->input->post('end_time');
$days = implode(',',$this->input->post('days'));
$objDateStart = DateTime::createFromFormat('Y-m-d h:i a', $new_batch_start_date.' '.$new_batch_start_time);
$objDateEnd = DateTime::createFromFormat('Y-m-d h:i a', $new_batch_end_date.' '.$new_batch_end_time);
if ($objDateEnd < $objDateStart) throw new Exception('End Date Should be Greater than Start Date');
if ($this->Batch_model->hasBatchesBetweenDates($objDateStart, $objDateEnd)) throw new Exception('Other Batch already running On from '.$objDateStart->format('d-m-Y H:i').' to '.$objDateEnd->format('d-m-Y H:i').'. Please Change Time Slot for Start and End Date');
$data = array(
'activity_list_id' => $this->input->post('activity_name'),
'batch_venue_id' => $venue_id,
'batch_name' => $this->input->post('batch_name'),
'start_date' => $objDateStart->format('Y-m-d'),
'end_date' => $objDateEnd->format('Y-m-d'),
'start_time' => $objDateStart->format('H:i'),
'end_time' => $objDateEnd->format('H:i'),
'total_capacity' => $this->input->post('total_capecity'),
'batch_status' => 1,
'created_by' => trim($this->session->userdata['login_data']['user_id']),
'created_date' => date('d-m-Y h:i:s A'),
'batch_days' => $days
);
$this->Batch_model->createBatch($data);
}
catch(Exception $e)
{
$arrError = [
'error' => false,
'msg' => $e->getMessage()
];
echo json_encode($arrError);
}
Model:
public function hasBatchesBetweenDates(DateTime $objDateStart, DateTime $objDateEnd)
{
$query = $this->db
->from('batch_list')
->join('activity_list','activity_list.activity_id = batch_list.activity_list_id')
->where('CONCAT(start_date,\' \',start_time) >=', $objDateStart->format('Y-m-d H:i:s'))
->or_group_start()
->where('CONCAT(end_date, \' \', end_time) <=', $objDateEnd->format('Y-m-d H:i:s'))
->where('CONCAT(end_date, \' \', end_time) >=', $objDateStart->format('Y-m-d H:i:s'))
->group_end()
->get();
return ($query->num_rows() > 0);
}
i hope you understand the concepts here - if you've questions - don't hesitate to ask
How to check if one UNIX timestamp range is overlapping another UNIX timestamp range in PHP?
I am developing an application which takes future reservations. But, only one (1) reservation is allowed per period.
Example:
Mr. X has a reservation for a resource from 10:00 A.M. to 12:00 P.M. (noon). Later, Ms. Y wants to reserve that same resource from 8:00 A.M. to 11:00 P.M.. My application should reject Ms. Y's attempted reservation because it overlaps Mr. X's prior reservation.
I am storing the start and end times of existing reservations in UNIX timestamps (integers), but I could convert them into the following format "yyyy-mm-dd hh:mm:ss" if required, or vice versa.
I do not understand how to solve this problem. If I check the new start time with all the existing reservation start times, and the new end time in a similar fashion, the logic will have many if statements and make the application slow.
Would you please help me to solve this issue in an efficient way without using lots of server resources.
Your help is greatly appreciated.
Thanks
Introduction
In other words, you need to do a comparison of all reservation intervals (UNIX timestamps) for a particular resource to determine if a new reservation is valid (within the domain for new reservations).
Step 1
First, a SQL query similar to this might help. While key words like ANY, ALL, NOT, EXISTS and others may seem tempting, it is up to you to decide how much information you need in the event of a scheduling conflict (based on your UI). This query provides the opportunity to extract the maximum amount of information (in PHP, etc ...) about a potential reservation with look ahead forecasting.
// A query like this might help. It's not perfect, but you get the idea.
// This query looks for ALL potential conflicts, starting and ending.
$sql = "SELECT DISTINCT `t1`.`startTime`, `t1`.`endTime`
FROM `reservations` AS `t1`
INNER JOIN `resources` AS `t2`
ON `t1`.`resourceId` = `t2`.`resourceId`
WHERE `t2`.`resourceId` = :resourceId
AND (`t1`.`startTime` BETWEEN :minTime1 AND :maxTime1)
OR (`t1`.`endTime` BETWEEN :minTime2 AND :maxTime2)
ORDER BY `t1`.`startTime` ASC";
Potentially. this will leave you with a multi-dimentional array. The following logic allows you to get a report detailing why the reservation cannot be made. It is up to you to interpret the report in another module.
Step 2
Generalize the solution as a methods of a Reservation class. Depending on your RDBMS, you may be able to do something like this in SQL. Although, it will probably be far less specific and you may want that granularity later. You could send the report in JSON format to a JavaScript front end (just something to think about).
private function inOpenDomain(array $exclusion, $testStart, $testEnd)
{
$result = null;
$code = null;
$start = $exclusion[0];
$end = $exclusion[1];
if (($testStart > $end) || ($testEnd < $start)) {
$result = true;
$code = 0; //Good! No conflict.
} elseif ($testStart === $start) {
$result = false;
$code = 1;
} elseif ($testStart === $end) {
$result = false;
$code = 2;
} elseif ($testEnd === $start) {
$result = false;
$code = 3;
} elseif ($testEnd === $end) {
$result = false;
$code = 4;
} elseif (($testStart > $start) && ($testEnd < $end)) { //Middle
$result = false;
$code = 5;
} elseif (($testStart < $start) && ($testEnd > $start)) { //Left limit
$result = false;
$code = 6;
} elseif (($testStart < $end) && ($testEnd > $end)) { //Right limit
$result = false;
$code = 7;
} elseif (($testStart < $start) && ($testEnd > $end)) { //Both limits
$result = false;
$code = 8;
} else {
$result = false;
$code = 9;
}
return ['start' => $start, 'end' => $end, 'result' => $result => 'code' => $code];
}
Step 3
Make a method that manages the checking of prior reservation times (assuming PDO::FETCH_ASSOC).
private function checkPeriods(array $periods, $newStartTime, $newEndTime)
{
$report = [];
if (!isset($periods[0])) { //If NOT multi-dimensional
$report = inOpenDomain($periods, $newStartTime, $newEndTime)
} else {
for ($i = 0, $length = $count($periods); $i < $length; ++$i) {
$report[$i] = inOpenDomain($periods[$i], $newStartTime, $newEndTime);
}
}
return $report;
}
Step 4
Fashion a method for doing a SELECT on the reservations table using a PDO prepared statement. Generally, ...
private function getReservationTimes($resourceId, $minTime, $maxTime)
{
$sql = "SELECT DISTINCT `t1`.`startTime`, `t1`.`endTime`
FROM `reservations` AS `t1`
INNER JOIN `resources` AS `t2`
ON `t1`.`resourceId` = `t2`.`resourceId`
WHERE `t2`.`resourceId` = :resourceId
AND (`t1`.`startTime` BETWEEN :minTime1 AND :maxTime1)
OR (`t1`.`endTime` BETWEEN :minTime2 AND :maxTime2)
ORDER BY `t1`.`startTime` ASC";
$stmt = $this->db->prepare($sql);
$stmt->bindParam(:resourceId , $resourceId);
$stmt->bindParam(:minTime1 , $minTime);
$stmt->bindParam(:maxTime1 , $maxTime);
$stmt->bindParam(:minTime2 , $minTime);
$stmt->bindParam(:maxTime2 , $maxTime);
$stmt->execute();
return $stmt->fetchAll();
}
Step 5
Make a public method (interface) for the entire process.
public function isOpen($minTime, $maxTime)
{
$periods = $this->getReservationTimes($this->resource->getResourceId(), $minTime, $maxTime);
if (empty($periods)) {
return true; //You may reserve the resource during the time period.
}
return $this->checkPeriods($periods, $this->start, $this->end));
}
Step 6
Separate the concerns.
Create a class hierarchy for the actual items being reserved.
abstact class Product
{
}
class Resource extends Product implements Reservable //Or, something ...
{
private $resourceId;
//etc ....
}
Create a class hierarchy for reservations.
abstract class Interval
{
private $start;
private $end;
public function __construct($start, $end)
{
$this->start = $start;
$this->end = $end;
}
}
class Reservation extends Interval
{
private $db;
private $resource;
public function __construct(PDO $pdo, Reservable $resource, $reqStartTime, $reqEndTime)
{
parent::__construct($reqStartTime, $reqEndTime);
$this->db = $pdo;
$this->resource = $resource;
}
}
Step 7
Run within try/catch
When you instantiate the Reservation object, supply at least a Reservable object, the requested start time, and requested end time (as UNIX timestamps, in this case).
try
{
$day = 84600; // Seconds per day.
$future = $day * 90; // Application specific.
//User requested times.
$reqStartTime = 1488394687 + $day; // Tomorrow.
$reqEndTime = 1488394687 + ($day * 2); // Two day duration.
//Search constraints.
$minTime = time(); // Today. Right now.
$maxTime = 1488394687 + $future; // 90 day look ahead.
$reservation = new Reservation($pdo, $resourceObj, $reqStartTime, $reqEndTime);
$availability = $reservation->isOpen($minTime, $maxTime);
if($availability === true){
$reservation->confirm();
} else {
//Have some other object deal with the report
$reporter = new Reporter($availability);
$reporter->analyzeReport();
//Have some other object update the view, etc ...
}
}
catch(Exception $e)
{
//Handle it.
}
I am using PHP and SQL Server to first request an HTML template stored in my database, and then update it in a different table in the database based on form input from my website.
my update function in my model uses a get_template function to pull the text from the database, then updates the table.
public function update_domain_rules($template_content, $domain_guid) {
$sql = "UPDATE domains
SET rules = ?
WHERE domain_guid = ?";
$query = $this->db->query($sql, array($template_content, $domain_guid));
return $query->result();
}
I need to be able to replace certain words in the template I pulled with variables in my controller, specifically the start date, end date, and the name of the domain that is selected in the dropdown, and then update the database. this is the code for my controller:
function content()
{
$this->load->model('domains_model');
$this->load->model('insert_rules_model');
$domain_guid = $this->input->post('edit_domain_guid');
$start_date = $this->input->post('start_date');
$end_date = $this->input->post('end_date');
$template = $this->input->post('select_template');
if ($start_date == '') {
$start_date ==date("m/d/Y",strtotime("-1 day"));
}
if ($end_date =='') {
$end_date ==date("m/d/Y",strtotime("-1 day"));
}
$start_date_formatted = date_create($start_date);
$end_date_formatted = date_create($end_date);
$template_name = array( //create array referenced in the form_dropdown in the view
'aliens_ep1_template',
'aliens_ep2_template',
'zombies_ep1_template',
'zombies_ep2_template'
);
$template_text = $this->insert_rules_model->get_template($template);
if ($template != null) {
foreach ($template_text as $row) {
$query = $this->insert_rules_model->update_domain_rules($row->template, $domain_guid);
}
}
//redirect ("admin/insert_rules");
$data = array(
'template_name' => $template_name,
'domains' => $this->domains_model->domain_dropdown_list(),
'start_date' => $start_date,
'end_date' => $end_date,
'domain_guid' => $domain_guid
);
$this->load->view('includes/header_admin');
$this->load->view('admin/insert_rules', $data);
$this->load->view('includes/footer_admin');
}
I am very new to PHP so forgive me if my code looks ugly. I am just trying to get this thing to be functional.
i am using jquery countdown timer but the problem is that timer start from value set every time on page refresh . I want to get time on first time and Save in PHP Session and subtract second time from frist time and update session etc. In Simple Word i want to create php countdown timer run only 50 using php
here is my controller code
public function actionViewtimer($id) {
$session = Yii::app()->session;
$this->layout = 'countdownlayout';
if (empty($session['countdowntime'])) {
$orderTime = microtime(true); #when user first time enter timer start from 50 mins
$session->add('countdowntime', array($orderTime)); //replace this line
} else {
$time_end = microtime(true);
$orderTime = $time_end - $time_start;
unset($session['countdowntime']);//unset old session
$session->add('countdowntime', array($orderTime)); //when user enter second
}
$getMinutes = $getMinutes_from_orderTime ; #please tell me how we extact minutes and pass them to view
$session->add('timersession', array($rand));
$this->render('viewtimerpage', array(
'getMinutes' => $getMinutes
));
}
here is my jquery code
<script>
$(function() {
$('#xlarge').countdowntimer({
minutes: 50<?php echo $getMinutes; ?>,
size: "lg",
timeUp: timeisUp
});
});
function timeisUp() {
alert('Time Complete');
return false;
}
</script>
Sorry, I've not used Yii so this example will be in plain PHP.
session_start();
if(!isset($_POST['counter']) || !is_array($_POST['counter')) {
$duration = 50;
$counter = array(
'start_time' => new DateTime()->format('Y-m-d H:i:s'),
'end_time' => new DateTime()->modify("+{$duration} minute")->format('Y-m-d H:i:s'),
'duration' => $duration
);
$_SESSION['counter'] = $counter;
}
$counter = $_POST['counter'];
$now = new DateTime();
$end_time = new DateTime($counter['end_time']);
$time_left = $end_time->getTimestamp() - $now->getTimestamp();
echo "{$time_left} seconds left";
This should be simple enough to convert, and you can easily convert seconds to minutes.
Don't destroy the session variable. Just set it the first time when its empty and then plug that value always into your countdown timer.
Inside you action
$session = Yii::app()->session;
$this->layout = 'countdownlayout';
if (empty($session['countdowntime'])) {
$date = new DateTime();
$date->modify('+50 minutes'); // Add 50 minutes to current time
$session['countdowntime'] = $date->format('Y/m/d H:i:s'); // Store date in session
}
$this->render('viewtimerpage', array(
'countdowntime' => $session['countdowntime'];
));
jQuery Code
$(function() {
$('#xlarge').countdowntimer({
dateAndTime : "<?php echo $countdowntime; ?>",
size: "lg",
timeUp: timeisUp
});
});
As I understand you want to show difference between 2 dates. Default value = 50 minutes(value for session if user first time opened page). If user refresh page after 10 minutes in view must show difference(40). It will be something like that:
public function actionViewtimer($id) {
$this->layout = 'countdownlayout';
/** #var CHttpSession $session */
$session = Yii::app()->session;
$minutes = 50; //default value for minutes
if (!$session->offsetExists('countdowntime')) {
$session->add('countdowntime', new DateTime()); //set value to session
} else {
$timeEnd = new DateTime();
/** #var DateTime $countDownTime */
$countDownTime = $session->get('countdowntime');
$interval = $countDownTime->diff($timeEnd);
$countMinutes = $interval->days * 24 * 60;
$countMinutes += $interval->h * 60;
$countMinutes += $interval->i;
$minutes -= $countMinutes;
$session->add('countdowntime', $timeEnd); //refresh value
}
// $session->add('timersession', array($rand)); don't know for what is it
$this->render('viewtimerpage', array(
'getMinutes' => $minutes
));
}
And js:
<script>
$(function() {
$('#xlarge').countdowntimer({
minutes: <?php echo $getMinutes; ?>, //without 50
I'm looking for a way to limit the attempts an user can make to login. I saw this plugin but it hasn't been updated in over 2 years.. and if available I always prefer a way that doesn't involve plugins. :)
Is there a variable that can be set in wp-config.php?
Otherwise, is there a way to achive this via webserver config? I have nginx 1.7.4.
I founded this class.
<?php
/**
* CLASS LIMIT LOGIN ATTEMPTS
* Prevent Mass WordPress Login Attacks by setting locking the system when login fail.
* To be added in functions.php or as an external file.
*/
if ( ! class_exists( 'Limit_Login_Attempts' ) ) {
class Limit_Login_Attempts {
var $failed_login_limit = 3; //Giris Denemesi
var $lockout_duration = 1800; //Sureyi sn cinsinden giriniz. 30 dakika: 60*30 = 1800
var $transient_name = 'attempted_login'; //Transient used
public function __construct() {
add_filter( 'authenticate', array( $this, 'check_attempted_login' ), 30, 3 );
add_action( 'wp_login_failed', array( $this, 'login_failed' ), 10, 1 );
}
/**
* Lock login attempts of failed login limit is reached
*/
public function check_attempted_login( $user, $username, $password ) {
if ( get_transient( $this->transient_name ) ) {
$datas = get_transient( $this->transient_name );
if ( $datas['tried'] >= $this->failed_login_limit ) {
$until = get_option( '_transient_timeout_' . $this->transient_name );
$time = $this->when( $until );
//Display error message to the user when limit is reached
return new WP_Error( 'too_many_tried', sprintf( __( '<strong>HATA</strong>: Kimlik dogrulama sinirina ulastiniz, %1$s sonra lutfen tekrar deneyiniz.' ) , $time ) );
}
}
return $user;
}
/**
* Add transient
*/
public function login_failed( $username ) {
if ( get_transient( $this->transient_name ) ) {
$datas = get_transient( $this->transient_name );
$datas['tried']++;
if ( $datas['tried'] <= $this->failed_login_limit )
set_transient( $this->transient_name, $datas , $this->lockout_duration );
} else {
$datas = array(
'tried' => 1
);
set_transient( $this->transient_name, $datas , $this->lockout_duration );
}
}
/**
* Return difference between 2 given dates
* #param int $time Date as Unix timestamp
* #return string Return string
*/
private function when( $time ) {
if ( ! $time )
return;
$right_now = time();
$diff = abs( $right_now - $time );
$second = 1;
$minute = $second * 60;
$hour = $minute * 60;
$day = $hour * 24;
if ( $diff < $minute )
return floor( $diff / $second ) . ' saniye';
if ( $diff < $minute * 2 )
return "yaklasik 1 dakika once";
if ( $diff < $hour )
return floor( $diff / $minute ) . ' dakika';
if ( $diff < $hour * 2 )
return 'yaklasik 1 saat once';
return floor( $diff / $hour ) . ' saat';
}
}
}
//Enable it:
new Limit_Login_Attempts();
Altough the post is quite old I will provide my findings because I couldn't find the answer myself until today.
Looked in the codex and whatnot, but everywhere I got ordered to use a plugin - which I do not want.
So to answer your question:
Is there a variable that can be set in wp-config.php?
No, there is not a variable you can set in wp-config.
Otherwise, is there a way to achive this via webserver config? I have nginx 1.7.4.
I am no webserver magician but I guess not.
But! - From this blog post by Etienne Tremel I got that there is a filter:
add_filter( 'authenticate', (...)
and function hook:
add_action( 'wp_login_failed', (...)
you can use to tap into the login-process. With that information I was able to anticipate on login-attempts with my own custom code.
In his blog-article you'll find a copy paste piece of code to dump in your functions.php file.
Protecting this kind of functionality is indeed best done outside this application and even it's programming language.
Denying connections is typically the task of a firewall and this also protects the webserver.
Put these two together you quickly arrive at fail2ban or sshguard. A hosting company I work with has done exactly that, so I know it's possible to do that. They use a four strikes and you're out policy. I'm not sure if their code is public, but it shouldn't be to hard to come up with a recipe, both have excellent documentation.
The best place to start would be downloading and looking under the hood of a plugin that already does this. Studying what methods can be employed will help you in your implementation regardless if the plugin is up to date or not.