|
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:
if(!$conn) $conn = mysqli_connect(C_HOST,C_USER,C_PASS,C_BASE) or die($w[113]);
Full code of the function is:
function all_online_users()
{
if(!$conn) $conn = mysqli_connect(C_HOST,C_USER,C_PASS,C_BASE) or die($w[113]);
$sec = 300;
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();
|
|
|
|
|
|
|
I'm testing my old PHP code with PHP 8.1 (code is working fine with PHP 7.4).
Following line is not working on PHP 8.1
$total += count($row[0]);
I tried with strlen but it gives totally wrong result because this count is counting messages, size of inbox.
if (!defined("_COMMON_")) {echo "stop";exit;}
include_once($ld_engine_path."inc_connect.php");
$m_result = mysqli_query($conn,"select new_mails from ".$mysql_table_prefix."users where id=$is_regist") or die("database error<br>".mysqli_error($conn));
if (mysqli_num_rows($m_result))
list($new_board_messages) = mysqli_fetch_array($m_result, MYSQLI_NUM);
if (!isset($new_board_messages)) $new_board_messages = "0";
mysqli_free_result($m_result);
$m_result = mysqli_query($conn,"select concat(subject,body) from ".$mysql_table_prefix."board where user_id=$is_regist") or die("database error: cannot retrieve mail-messages<br>".mysqli_error($conn));
$total = 0;
while ($row = mysqli_fetch_array($m_result, MYSQLI_NUM))
$total += count($row[0]);
$percentage = round($total / $max_mailbox_size *100);
mysqli_free_result($m_result);
|
|
|
|
|
What does "not working" mean, what are you trying to count?
|
|
|
|
|
You haven't explained what "not working" means. The only notable difference documented in that function between v7 and v8 is:
Prior to PHP 8.0.0, if the parameter was neither an array nor an object that implements the Countable interface, 1 would be returned, unless value was null, in which case 0 would be returned.
So either you're now getting a TypeError where previously you were just counting the number of rows; you're now getting the sum of the string lengths, whereas previously you were counting the number of rows; or something else is happening, which you haven't explained.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You are correct, previously it was counting number of rows, now it's counting string lenghths which is not the requirement.
Please suggest me a solution
|
|
|
|
|
Replace:
$total += count($row[0]); with:
$total += 1;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes it worked!!
Thank you!
|
|
|
|
|
I'm trying to migrate my PHP code which is working on PHP 7.4 to PHP 8.1.
With PHP 8.1, following
if($message_id == "") {
code is triggering for logged in users too.
Can somebody point out common errors in this code?
require_once("inc_common.php");
include($engine_path."users_get_list.php");
set_variable("message_id");
set_variable("send_to");
set_variable("send_to_id");
$send_to_id = intval($send_to_id);
if (!$exists) {
$error_text = "$w_no_user";
include($file_path."designes/".$design."/error_page.php");
exit;
}
$u_ids = array();
$u_names = array();
$tmp_body = "";
$tmp_subject = "";
$info_message = "";
if($message_id == "") {
if ($send_to!="") {
$user_to_search = $send_to;
include($ld_engine_path."users_search.php");
if (!count($u_ids)) $info_message = "".str_replace("~",""".htmlspecialchars($send_to).""",$w_search_no_found)."<br>";
}
if ($send_to_id!="") {
include("inc_user_class.php");
$ttt = $is_regist;
$is_regist = $send_to_id; #fake again :(
include($ld_engine_path."users_get_object.php");
$u_ids[] = $is_regist;
$is_regist = $ttt;
$u_names[] = $current_user->nickname;
}
}
else {
$board_operation = "reply";
$id = $message_id;
include($ld_engine_path."board_process_message.php");
$u_ids[] = $board_message["from_id"];
$u_names[] = $board_message["from"];
$tmp_body = str_replace("<br>","\n",$board_message["body"]);
$tmp_body = "\n\n_______ ".str_replace("~", $board_message["from"], $w_user_wrote)." ______\n$tmp_body";
$tmp_subject = str_replace("\"",""","Re: ".$board_message["subject"]);
}
include($file_path."designes/".$design."/board_send.php");
modified 30-Mar-23 1:04am.
|
|
|
|
|
The only place that variable is mentioned prior to the test is the set_variable("message_id"); line.
As far as I can see, that's not a built-in PHP function. So you need to check what that function is doing, and try to work out why its behaviour has changed in PHP 8.
We can't do that for you, since we can't see the function.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you for the tip.
I will check it
|
|
|
|
|
The issue has been resolved after adding null by replacing ""
Old code:
if ($send_to_id!="") {
New code:
if ($send_to_id!=null) {
But will it do the same?
|
|
|
|
|
I'm trying to migrate my PHP code which is working on PHP 7.4 to PHP 8.1.
With PHP 8.1, following "if" code executes Javascript but with PHP 7.4 it didn’t execute Js part and it was the normal state.
If I use null instead of “” after the != will it fix this? and is it correct?
if ($error != "") echo "<script>alert('".str_replace("<br>","\\n",str_replace("\n","\\n",str_replace("\r","",str_replace("'","\'",$error_text))))."');</script>";
|
|
|
|
|
I have tried that code in version 7 and 8 and get the same results in both. You need to provide some more details.
|
|
|
|
|
My code is working on PHP 7.4 and now I'm testing it with PHP 8 and getting following error_log:
PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in D:\localhost\htdocs\chat\dtc\engine\mysql\board_alerter.php:13
board_alerter.php is as given below:
<?php
if (!defined("_COMMON_")) {echo "stop";exit;}
include_once($ld_engine_path."inc_connect.php");
$m_result = mysqli_query($conn,"select new_mails from ".$mysql_table_prefix."users where id=$is_regist") or die("database error<br>".mysqli_error($conn));
if (mysqli_num_rows($m_result))
list($new_board_messages) = mysqli_fetch_array($m_result, MYSQLI_NUM);
if (!isset($new_board_messages)) $new_board_messages = "0";
mysqli_free_result($m_result);
$m_result = mysqli_query($conn,"select concat(subject,body) from ".$mysql_table_prefix."board where user_id=$is_regist") or die("database error: cannot retrieve mail-messages<br>".mysqli_error($conn));
$total = 0;
while ($row = mysqli_fetch_array($m_result, MYSQLI_NUM))
$total += count($row[0]);
$percentage = round($total / $max_mailbox_size *100);
mysqli_free_result($m_result);
?>
Please suggest me a fix
|
|
|
|
|
Replacing count($row[0]); with strlen($row[0]); should do it.
|
|
|
|
|
Yes it worked!!
Thank you!
|
|
|
|
|
I'm having a htaccess redirection issue which I am unable to find a solution by searching on the Internet and also I did several htaccess rewrite codes, but nothing helped me.
The URL has a part %3F
Please give me a correct solution to redirect following URL using htaccess:
https://www.example.com/folder/%3F
to
https://www.example.com/folder/
modified 11-Mar-23 1:49am.
|
|
|
|
|
Quote: In this game you can develop whatever technologies. But you want to implement smile API.
Smile API just provide image and Solutions(Solution always come 1-9 Numbers ). image have simple maths quiz.
Every Time you call smile API ,Image and solution will be change.
You can do like quiz application. You want to validate that solution with user's answer.
You want to add this 3 components in this game
1.Software architecture- it's like model view controller, clean Architecture
2.even driven architecture- it's like GUI (login, Register)and buttons.
3.Interoperability - it's mean Use Smile Api
And you can get extra marks for Extra features. Question is the image .API response should be the solution.
Quote: When the Login button is pressed, initialize the game and call the API .Send the HTTP Get Request using API .After Login starts GUI .When initialized the game appears the question . When the user answers the question, Solution becomes the API Response and passes the data to the JSON object .Validate the Solution with the user's answer .If the user's input is equal to the solution (calculation is correct) the user can go to the next level and increase the score and also call the API .Quote: When calling the API get the data and divide into the string variables .In this need JSON array() instead of JSON object
|
|
|
|
|
Is this supposed to be a question or a statement of intent?
I have deleted your reposts of this question; please do not spam the forums.
|
|
|
|
|
Hey guys,
I run into a problem with developing a new project of mine, more specifically with a shortcode of mine.
About the website setup:
- I use wordpress
- I use Elementors template option to print out a template on on all pages belonging to the taxonomy "Marken".
- Custom post types are created with CPT UI and custom fields with ACF
I got the following shortcode, to print out the specific brand on the site iteself:
add_shortcode( 'MODELL', 'modell_shortcode' );
function modell_shortcode() {
$terms = get_the_terms( array(
'post_type' => 'fahrzeuge',
'taxonomy' => 'marken',
'hide_empty' => false,
) );
return ucwords($terms[1]->slug);
}
The code works fine put prints out the wrong brand. As you can see here Tesla – moinmobility.de[^] "Tesla" should be written in the text above but "Audi" is shown.
The same issue applies for the other shortcodes there should be written "0 €" instead of "345 €" etc.
Is this a problem with my shortcode? With Elementor? And how to fix this?
Searched a lot on Google, Blogposts and Forums but couldn't find a helpful answear. Hope someone here can help me
|
|
|
|
|
Add the following code however when executing it does not show the page
<?php
session_name('10421941204desarrollocartera');
session_start();
if(empty($_SESSION['authenticated_user_roleid']) && !isset($_GET['type_auth'])){
header('Location: /desarrollocartera');
}
?>
<!DOCTYPE html>
<html>
<?php ?>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<link rel="shortcut icon" href="/desarrollocartera/themes/images/favicon.ico" type="image/x-icon">
<title>Fideicomisos</title>
<!--
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="css/elfinder.min.css">
<link rel="stylesheet" type="text/css" href="css/theme.css">
<!--
<script src="js/jquery.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/elfinder.min.js"></script>
<style>
.elfinder{
width: 100%;
height: 99.7vh!important;
border: none;
}
body{
margin: 0px;
padding: 0px;
}
.elfinder-contextmenu-item .elfinder-button-icon-rm.elfinder-contextmenu-extra-icon,
.elfinder-contextmenu-item .elfinder-button-icon-link.elfinder-contextmenu-extra-icon{
display: none !important;
}
span.elfinder-navbar-root-trash {
<?php if($_SESSION['authenticated_user_roleid'] != 'H2'): ?>
display: none;
<?php endif; ?>
}
</style>
</head>
<body>
<div id="finder"></div>
<script>
var tipo = '<?php echo $_GET['tipo']; ?>';
var pago = '<?php echo $_GET['pago']; ?>';
var id = '<?php echo $_GET['contrato']; ?>';
</script>
<script src="config.js"></script>
</body>
</html>
|
|
|
|
|
Hi, I want to run Project laravel on an Linux server Aapnel panel and my project is api but I have a cors error and I want to know how the subdomain is defined on this panel is not the shape of other cpanel at all, its environment, thank you for your help
|
|
|
|
|
<?php
session_start();
ini_set('display_errors', 1);
error_reporting(E_ALL);
define("PRODUCTIMAGE",0);
define("PRODUCTCODE", 1);
define("PRODUCTNAME", 2);
define("QUANTITY", 3);
define("PRICE", 4);
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (isset($_POST['productcode']))
{
AddToCart();
}
else
{
$action = isset($_POST['action']) ? $_POST['action'] : '';
$value = strtoupper(substr($action, 0, 5));
switch ($value)
{
case "CONTI":
header("Location: "."products.html");
break;
case "RECAL":
RecalculateCart();
break;
case "CHECK":
header("Location: "."customer.php");
break;
}
}
}
function AddToCart()
{
$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : '';
$itemcount = isset($_SESSION['itemcount']) ? $_SESSION['itemcount'] : 0;
$productname = $_POST['productname'];
$extra_price = 0;
$productname = stripslashes($productname);
for ($i=0; $i < $itemcount; $i++)
{
if ($cart[PRODUCTNAME][$i] == $productname) {
$cart[QUANTITY][$i] = $cart[QUANTITY][$i] + intval($_POST['quantity']);
$_SESSION['cart'] = $cart;
$_SESSION['itemcount'] = $itemcount;
header("Location: "."cart.php");
exit;
}
}
$cart[PRODUCTIMAGE][$itemcount] = $_POST['productimage'];
$cart[PRODUCTCODE][$itemcount] = $_POST['productcode'];
$cart[PRODUCTNAME][$itemcount] = $_POST['productname'];
$cart[QUANTITY][$itemcount] = intval($_POST['quantity']);
$cart[PRICE][$itemcount] = $_POST['price'];
$itemcount = $itemcount + 1;
$_SESSION['cart'] = $cart;
$_SESSION['itemcount'] = $itemcount;
}
function RecalculateCart()
{
$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : '';
$itemcount = isset($_SESSION['itemcount']) ? $_SESSION['itemcount'] : 0;
for ($i=0; $i<$itemcount; $i++)
{
$quantity = $_POST['quantity'.($i)];
if (empty($quantity))
{
$quantity = 0;
}
else
if (($quantity < 0) || (!is_numeric($quantity)))
{
$quantity = 0;
}
$cart[QUANTITY][$i] = intval($quantity);
}
for ($j=0; $j<$itemcount; $j++)
{
$quantity = $cart[QUANTITY][$j];
if ($quantity == 0)
{
$itemcount--;
$curitem = $j;
while(($curitem+1) < count($cart[0]))
{
for ($k=0; $k<4; $k++)
{
$cart[$k][$curitem] = $cart[$k][$curitem+1];
$cart[$k][$curitem+1] = '';
}
$curitem++;
}
}
}
$_SESSION['itemcount'] = $itemcount;
$_SESSION['cart'] = $cart;
}
?>
modified 29-Apr-22 3:30am.
|
|
|
|
|