Click here to Skip to main content
15,887,992 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
AnswerRe: PHP isset for an Array Pin
Richard MacCutchan6-Apr-23 6:06
mveRichard MacCutchan6-Apr-23 6:06 
GeneralRe: PHP isset for an Array Pin
Aruna KN8-Apr-23 5:06
Aruna KN8-Apr-23 5:06 
GeneralRe: PHP isset for an Array Pin
Richard MacCutchan8-Apr-23 5:09
mveRichard MacCutchan8-Apr-23 5:09 
GeneralRe: PHP isset for an Array Pin
Aruna KN8-Apr-23 5:19
Aruna KN8-Apr-23 5:19 
GeneralRe: PHP isset for an Array Pin
Aruna KN8-Apr-23 5:25
Aruna KN8-Apr-23 5:25 
GeneralRe: PHP isset for an Array Pin
Richard MacCutchan8-Apr-23 5:33
mveRichard MacCutchan8-Apr-23 5:33 
GeneralRe: PHP isset for an Array Pin
Aruna KN8-Apr-23 5:55
Aruna KN8-Apr-23 5:55 
QuestionPHP Warning: Undefined variable $conn Pin
Aruna KN3-Apr-23 2:45
Aruna KN3-Apr-23 2:45 
Following code is working fine up to PHP 7.4 but with PHP 8.1 it makes an error_log:

PHP Warning: Undefined variable $conn

Please suggest me a solution for this issue.

The relevant code line is:
PHP
if(!$conn) $conn = mysqli_connect(C_HOST,C_USER,C_PASS,C_BASE) or die($w[113]);


Full code of the function is:
PHP
function all_online_users()
{
    if(!$conn) $conn = mysqli_connect(C_HOST,C_USER,C_PASS,C_BASE) or die($w[113]);
    
  $sec = 300;
  //exit;
	if(isset($_SESSION['m']))
	{
		$user = is_numeric($_SESSION['m']) ? $_SESSION['m'] : 0;
		$MyAccess = 0;
       
	}
	else
	{
		$user = 0;
		$MyAccess = -1;
	}
	$ip = ($user == 0) ? ip2int(ip()) : 0;
  mysqli_query($conn,"DELETE FROM ".C_MYSQL_ONLINE_USERS." WHERE (time < DATE_SUB(NOW(), INTERVAL ".$sec." SECOND) AND NOW() > ".$sec.") or time > NOW()");
  $result = @mysqli_query($conn,"SELECT * FROM ".C_MYSQL_ONLINE_USERS);
	$cnt=array();$adduser=1;$addguest=1;$users=0;
	while($result && $i = mysqli_fetch_array($result))
	{
		$cnt[$i['usertype']] = (isset($cnt[$i['usertype']])) ? $cnt[$i['usertype']] + 1 : 1;
		If(($MyAccess >= 0) && ($user == $i['user'])) 
		{
			$adduser=$addguest=0;
		}
		If(($MyAccess < 0) && ($ip == $i['ip'])) 
		{
			$adduser=$addguest=0;
		}
	}
	if($adduser || $addguest)
	{
	    mysqli_query($conn,"INSERT INTO ".C_MYSQL_ONLINE_USERS." VALUES (NOW(),".$user.",'".$MyAccess."','".$ip."')");
		$cnt[$MyAccess] = (isset($cnt[$MyAccess])) ? $cnt[$MyAccess] + 1 : 1;
	}
	$k=0;while(isset($cnt[$k]))
	{
		$users = $cnt[$k] + $users;
		$k++;
	}
	if(isset($cnt['-1'])) define('ONLINE_GUESTS',$cnt['-1']);
	else define('ONLINE_GUESTS','0');
	define('ONLINE_USERS',$users);
}

all_online_users();

AnswerRe: PHP Warning: Undefined variable $conn Pin
Richard MacCutchan3-Apr-23 2:50
mveRichard MacCutchan3-Apr-23 2:50 
GeneralRe: PHP Warning: Undefined variable $conn Pin
Aruna KN3-Apr-23 3:48
Aruna KN3-Apr-23 3:48 
QuestionPHP 8.1 Count issue Pin
Aruna KN30-Mar-23 0:06
Aruna KN30-Mar-23 0:06 
AnswerRe: PHP 8.1 Count issue Pin
Richard MacCutchan30-Mar-23 0:45
mveRichard MacCutchan30-Mar-23 0:45 
AnswerRe: PHP 8.1 Count issue Pin
Richard Deeming30-Mar-23 0:45
mveRichard Deeming30-Mar-23 0:45 
GeneralRe: PHP 8.1 Count issue Pin
Aruna KN30-Mar-23 1:38
Aruna KN30-Mar-23 1:38 
GeneralRe: PHP 8.1 Count issue Pin
Richard Deeming30-Mar-23 2:53
mveRichard Deeming30-Mar-23 2:53 
GeneralRe: PHP 8.1 Count issue Pin
Aruna KN30-Mar-23 3:21
Aruna KN30-Mar-23 3:21 
QuestionIf command triggering at wrong time with PHP 8.1 Pin
Aruna KN29-Mar-23 18:56
Aruna KN29-Mar-23 18:56 
AnswerRe: If command triggering at wrong time with PHP 8.1 Pin
Richard Deeming29-Mar-23 21:22
mveRichard Deeming29-Mar-23 21:22 
GeneralRe: If command triggering at wrong time with PHP 8.1 Pin
Aruna KN29-Mar-23 21:27
Aruna KN29-Mar-23 21:27 
GeneralRe: If command triggering at wrong time with PHP 8.1 Pin
Aruna KN29-Mar-23 22:15
Aruna KN29-Mar-23 22:15 
QuestionBlank space or NULL with PHP 8.1 Pin
Aruna KN14-Mar-23 22:57
Aruna KN14-Mar-23 22:57 
AnswerRe: Blank space or NULL with PHP 8.1 Pin
Richard MacCutchan15-Mar-23 7:10
mveRichard MacCutchan15-Mar-23 7:10 
QuestionPHP Fatal error: Uncaught TypeError: count() Pin
Aruna KN10-Mar-23 20:17
Aruna KN10-Mar-23 20:17 
AnswerRe: PHP Fatal error: Uncaught TypeError: count() Pin
Graham Breach11-Mar-23 1:45
Graham Breach11-Mar-23 1:45 
GeneralRe: PHP Fatal error: Uncaught TypeError: count() Pin
Aruna KN11-Mar-23 16:32
Aruna KN11-Mar-23 16:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.