From 4f2666438811a4c0d22d00f96ff5ad840e7ff4b4 Mon Sep 17 00:00:00 2001 From: Jonathan Rosenbaum Date: Thu, 14 Mar 2019 06:31:00 +0000 Subject: [PATCH] Closes #86 using regexp solution. Should work well as long as the network doesn't change. I considered doing a straight-out IP swap during the 24hr period for such an unusual scenario, however, that would not allow for any separation of location if a shop is opened somewhere else. --- Connections/database_functions.php | 36 ++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/Connections/database_functions.php b/Connections/database_functions.php index 2bc61d6..5238ed5 100644 --- a/Connections/database_functions.php +++ b/Connections/database_functions.php @@ -1,12 +1,11 @@ setErrorsHandlerLevel(E_ALL &~ E_DEPRECATED); $handler->start(); -*/ // DO NOT EDIT - USE Connections/local_configurations.php instead with definitions between // ) ? > @@ -26,6 +25,20 @@ $handler->start(); */ if( !defined( 'TIMEZONE' ) ) define("TIMEZONE", "America/New_York"); +/*** +DHCP +****/ +// The public IP address of the device which has opened a shop determines the ownership of that shop. +// In that way, more than one shop can run without conflicting with each other from different locations. +// However, in some cases the IP changes frequently due to DHCP during a 24hr shop. +// Definitions: +// default (use full IP address assigned) +// or +// Enter the numbers that defines a Class (A|B|C) Network, eg. 73.79; +// 73.79 would match a Class B network with an IP range of 73.79.*.* +// For additional info, read https://www.webopedia.com/DidYouKnow/Internet/IPaddressing.asp +if( !defined( 'IP' ) ) define("IP", "default"); + /********* MEMBERSHIP **********/ @@ -883,11 +896,20 @@ function current_shop_by_ip(){ $IP = $_SERVER['REMOTE_ADDR']; $current_date = current_date(); - mysql_select_db($database_YBDB, $YBDB); - $query_Recordset1 = "SELECT shop_id FROM shops WHERE ip_address = '{$IP}' AND date REGEXP '^{$current_date} ' ORDER BY shop_id DESC;"; - $Recordset1 = mysql_query($query_Recordset1, $YBDB) or die(mysql_error()); - $row_Recordset1 = mysql_fetch_assoc($Recordset1); - $totalRows_Recordset1 = mysql_num_rows($Recordset1); + mysql_select_db($database_YBDB, $YBDB); + + if( IP == "default") { + $query_Recordset1 = "SELECT shop_id FROM shops WHERE ip_address = '{$IP}' AND date REGEXP '^{$current_date} ' ORDER BY shop_id DESC;"; + $Recordset1 = mysql_query($query_Recordset1, $YBDB) or die(mysql_error()); + $row_Recordset1 = mysql_fetch_assoc($Recordset1); + $totalRows_Recordset1 = mysql_num_rows($Recordset1); + } else { + $ip = IP; + $query_Recordset1 = "SELECT shop_id FROM shops WHERE ip_address REGEXP '^{$ip}' AND date REGEXP '^{$current_date} ' ORDER BY shop_id DESC;"; + $Recordset1 = mysql_query($query_Recordset1, $YBDB) or die(mysql_error()); + $row_Recordset1 = mysql_fetch_assoc($Recordset1); + $totalRows_Recordset1 = mysql_num_rows($Recordset1); + } return $row_Recordset1['shop_id']; }