Browse Source

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.
devel
Jonathan Rosenbaum 6 years ago
parent
commit
4f26664388
  1. 36
      Connections/database_functions.php

36
Connections/database_functions.php

@ -1,12 +1,11 @@
<?php <?php
require_once('YBDB.php'); require_once('YBDB.php');
/*
require_once(realpath($_SERVER["DOCUMENT_ROOT"]) . '/php-console/src/PhpConsole/__autoload.php'); require_once(realpath($_SERVER["DOCUMENT_ROOT"]) . '/php-console/src/PhpConsole/__autoload.php');
$handler = PhpConsole\Handler::getInstance(); $handler = PhpConsole\Handler::getInstance();
$handler->setErrorsHandlerLevel(E_ALL &~ E_DEPRECATED); $handler->setErrorsHandlerLevel(E_ALL &~ E_DEPRECATED);
$handler->start(); $handler->start();
*/
// DO NOT EDIT - USE Connections/local_configurations.php instead with definitions between // DO NOT EDIT - USE Connections/local_configurations.php instead with definitions between
// <?php (no space between ? and >) ? > // <?php (no space between ? and >) ? >
@ -26,6 +25,20 @@ $handler->start();
*/ */
if( !defined( 'TIMEZONE' ) ) define("TIMEZONE", "America/New_York"); 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 MEMBERSHIP
**********/ **********/
@ -883,11 +896,20 @@ function current_shop_by_ip(){
$IP = $_SERVER['REMOTE_ADDR']; $IP = $_SERVER['REMOTE_ADDR'];
$current_date = current_date(); $current_date = current_date();
mysql_select_db($database_YBDB, $YBDB); 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()); if( IP == "default") {
$row_Recordset1 = mysql_fetch_assoc($Recordset1); $query_Recordset1 = "SELECT shop_id FROM shops WHERE ip_address = '{$IP}' AND date REGEXP '^{$current_date} ' ORDER BY shop_id DESC;";
$totalRows_Recordset1 = mysql_num_rows($Recordset1); $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']; return $row_Recordset1['shop_id'];
} }

Loading…
Cancel
Save