Prevent WordPress from serializing meta data at meta update

On clicking on a div, I get the "data-animal" attribute (js function).

<div data-animal="dog"></div>
<div data-animal="cat"></div>
<div data-animal="pig"></div>

With my ajax call, I send it to this php function:

add_action( 'wp_ajax_animals', 'user_animals' );
add_action( 'wp_ajax_nopriv_animals', 'user_animals' );
function user_animals() {

$user = wp_get_current_user();
$animals_all = $_POST['animal'];

// get every animal as single row
add_user_meta($user->ID, 'animals_all' , $animal);

// get all animals of the same user
$wp_user_search = new WP_User_Query( array( 'fields' => 'animal' ) );
$get_users = $wp_user_search->get_results();

// now put all animals into one row
update_user_meta($user->ID, 'animals_all' , $get_users);

// delete the single row(s)
delete_user_meta($user->ID, 'animal');
}

My problem: WordPress serialize the data automatically. How can I undo or prevent WordPress from doing that? maybe_serialize / maybe_unserialize isn’t working.

How it is at my sql at the moment (just an example):

animals_all | a:8:{i:0;s:31:"cat";i:1;s:57:"dog";i:2;s:19: ...

How I need it at my sql:

animals_all | cat,dog,pig

pros and cons of high php session.sid_bits_per_character and session.sid_length?

As the title asks,

What are the pros and cons of high php session.sid_bits_per_character and session.sid_length?
The obvious pros are that the higher bits and length means even harder to brute force or overlaps, but is there much or any cons aside from the vague compatibility problem?

I ask this as that is as much information the manual provides.
https://www.php.net/manual/en/session.configuration.php#ini.session.hash-function

I can imagine possible cons, but these are at most dumb guesses.

  • longer length means bigger cookies and longer processing, also longer for RDBS id matching (with the unique, key column constraints? But as a key column, shouldn’t matter right?)
  • longer to generate? Maybe but probably by an impactable amount??

Is there any reason NOT to change these 2 settings to the following in the php.ini file?

sid_bits_per_character = 6
sid_length = 256

DTOs and getting data from a database? [closed]

I understand DTOs and they are useful to keep data consistent.

All the examples I see use a DTO to transform data coming into an application from a request, but not data coming out of a database.

It got me thinking, should you use a DTO with data coming out of a database, Surely the data is consistent as the source is known to you (as it is your database)?

Sticky product summary on Woocommerce single product page

I need to make the product summary on the Woocommerce single product page sticky. I have

.summary.entry-summary{
 position:sticky;
 top:100px
}

And this work, but the summary now sticks even when you have reached the produt tabs and goes on top of these. How can I make the summary stop being sticky when it reaches the product tab section?

CSRF TEST and mismatched value trouble

<!doctype html> 

<meta charset="utf-8"> 


<title> T CSRF_TEST.php </title>

<style> html * { font-size:1.75rem; font-family:monospace; } </style>

<?php
// Generate a CSRF token and store it in a cookie
$csrfToken = bin2hex(random_bytes(32));
setcookie("csrfToken", $csrfToken, time() + 3600);


?>


<form action="CSRF_TEST.php" method="POST">
<input type="hidden" name="csrfToken" value="<?php echo $_COOKIE['csrfToken']; ?>">

<input type="submit" value="Submit" onclick="refreshPage()">

</form>

<?php
echo "<br>";

$TOKEN = $_POST["csrfToken"];
echo "<br>TOKEN= " . $TOKEN;

$TOKEN2 = $_COOKIE['csrfToken'];
echo "<br>TOKEN2= " . $TOKEN2;

// On the server side, verify the CSRF token
if ($_POST['csrfToken'] !== $_COOKIE['csrfToken']) {
  // CSRF token mismatch
  // Reject the request
  echo "<br>";
  echo "Reject the request";
}
else
{
  echo "APPROVED REQUEST";
}

?>

<script>
function refreshPage() {
  window.location.replace("CSRF_TEST.php");
}
</script>

I am running this program and obtain two different value in the conditional ($_POST[‘csrfToken’] !== $_COOKIE[‘csrfToken’]) test . As I know the generative CSRF token is stored in cookie then the same is POST to php and i cannot realize why the values are different.

How can I edit an existing pdf using pdftk?

I hvae searched on google, stackoverflow and ChatGPT. I can’t find clear instructions on how to edit existing text or fill out a text field. I have checked the documentation and didn’t find anything that was really useful to me. Maybe I didn’t see something?

Anyway, I’m trying to fill out a text field in a pdf (Replacing a piece of text would also be a solution).

This is the code I have atm:

<?php

    $inputPdf = 'Test.pdf';
    $outputPdf = 'TestFertig.pdf';

    $FormFieldData = [
        'tbDocNum' => '123456',
        'tbTest' => 'Keine Ahnung alda',
    ];

    $pdftkCommand = "pdftk $inputPdf fill_form $inputPdf output $outputPdf";

    foreach ($FormFieldData as $fieldname => $fieldValue) {
        $pdftkCommand .= "flatten_fields output - ";
        $pdftkCommand .= "xfdf - < <(echo '<?xml version="1.0" encoding="UTF-8" ?><fields><field name="$fieldName"><value>$fieldValue</value></field></fields>') ";
    }

    exec($pdftkCommand);

    header('Content-type: application/pdf');
    readfile($outputPdf);

?>

I hope this is clear enough and thank you in advance.

Deprecated: Creation of dynamic property db::$required is deprecated [duplicate]

Deprecated: Creation of dynamic property db::$required is deprecated in /home1/include/connection.php on line 24

Fatal error: Uncaught Error: Object of class mysqli could not be converted to string in /home1/include/connection.php:27 Stack trace: #0 /home1/include/connection.php(471): db->__construct() #1 /home1/include/index.php(1): include(‘/home1/…’) #2 {main} thrown in /home1/include/connection.php on line 27

My Code:

class db
{
    var $iConn;
    private $dbHost;
    private $dbUser;
    private $dbPass;
    private $dbName;

    public function __construct(){
        $this->dbHost = "localhost";
        $this->dbUser = "thewcmp_automation";
        $this->dbPass = "6K_l+W)74Sv5";
        $this->dbName = "thewcmp_dashboard";
            
        $iConn = $this->required = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, $this->dbName);

        //check connection
        if (mysqli_connect_errno($this->$iConn))
        {
            echo "Failed to connect to MySQL:" . mysqli_connect_error();
        }
    }
}

Is this bcoz of PHP version? or any help please.

Can any one guide me or correct the Code for me please. Thanks in advance

Configure PHPMailer with Amazon SES dedicated IP

I have an dedicated IP address on Amazon SES but I don’t know how to find these informations I use for Amazon shared IP I put in my PHP file:

$configEmail['Host'] = 'email-smtp.us-east-2.amazonaws.com';
$configEmail['SMTPAuth'] = TRUE;
$configEmail['Username'] = 'AKIAW7D...';
$configEmail['Password'] = 'BFFuNfJO...';
$configEmail['Port'] = 587;
$configEmail['SMTPSecure'] = 'tls';

enter image description here

I do have a new user since I created this dedicated IP address and I have found the Access key of this new user in the menu “Identity and Access Management -> IAM > Users” but no password anywhere found and no host as well found.

Where to find these information?

Issues with Laravel groupBy

I am using Laravel 10.

This is crm_details table:

crm_details table

I need to count each status, that is Yes 3, No 3. Also I need to consider parent_token with the same value as a single row for that I have used the following query:

$salesCounts = DB::table('crm_details')
    ->select( DB::raw('count(crm_details.status) as count'),'crm_details.parent_token')
    ->groupBy('crm_details.status', 'crm_details.parent_token')
    ->get();

dd($salesCounts);

But I am getting all the data, what is wrong?

Java Tasks or Projects to do [closed]

My purpose for this topic is to have more information on my Java journey, I would like to know where I can take on [b]Java Tasks or Project[/b] that I can add to my GitHub/portfolio, please also any other related pieces of information you can help me with that can promote my knowledge in java would also go a long way.

Gbenga

I want to add projects and personal tasks to my portfolio to begin with

Codeigniter 3 memcached issue

i’m getting this error in my drivers/Cache_memcached.php file

A PHP Error was encountered
Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: drivers/Cache_memcached.php

Line Number: 120

i have downloaded 5.6 memcached ptted in php/ext/ but i’m getting this error in CI3 with php 5.6
i’m getting $this->_config = NULL value

please help me out anyone thanx in advance

Can’t show image after crop by CropperJS . Help me fix

I want to create the basic form can scale and crop by php. This is my step
Process.php

<?php
// Bật báo cáo lỗi và hiển thị lỗi
error_reporting(E_ALL);
ini_set('display_errors', 1);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Nhận dữ liệu ảnh sau khi cắt từ dạng base64
    $croppedImageBase64 = $_POST['croppedImage'];

    // Chuyển đổi dữ liệu base64 thành tệp ảnh
    $croppedImage = base64_decode(preg_replace('#^data:image/w+;base64,#i', '', $croppedImageBase64));

    // Đường dẫn lưu trữ tệp ảnh đã cắt
    $croppedImagePath = '/home/sam15997/public_html/test/test1/cropped_image.jpeg';

    // Lưu ảnh đã cắt
    if (file_put_contents($croppedImagePath, $croppedImage) === false) {
        echo 'Có lỗi xảy ra khi lưu tệp ảnh.';
        exit();
    }

    // Kiểm tra xem tệp ảnh đã cắt có tồn tại
    if (!file_exists($croppedImagePath)) {
        echo 'Tệp ảnh đã cắt không tồn tại.';
        exit();
    }

    // Tải tệp ảnh đã cắt về máy tính
    header('Content-Length: ' . filesize($croppedImagePath));
    header('Content-Type: image/jpeg');
    header('Content-Disposition: attachment; filename="cropped_image.jpeg"');
    readfile($croppedImagePath);

    // Xóa tệp ảnh đã cắt sau khi tải về
    if (unlink($croppedImagePath) === false) {
        echo 'Có lỗi xảy ra khi xóa tệp ảnh đã cắt.';
        exit();
    }

    // Kết thúc
    exit();
}
?>

And this Script.js

document.addEventListener('DOMContentLoaded', function () {
    // Chọn input tải ảnh và div hiển thị ảnh và công cụ cắt
    var imageInput = document.getElementById('imageInput');
    var previewImage = document.getElementById('previewImage');
    var imageCrop = document.getElementById('imageCrop');

    // Khởi tạo CropperJS với cấu hình tùy chỉnh
    var cropper = new Cropper(previewImage, {
        aspectRatio: 2/3, // Kích thước 40x60 (rất tiện lợi)
        zoomable: true,
        scalable: true,
        crop: function (e) {
            // Lấy thông tin vùng cắt
            var data = cropper.getData();
            var croppedCanvas = cropper.getCroppedCanvas();

            // Cập nhật vùng hiển thị ảnh cắt
            imageCrop.innerHTML = '';
            imageCrop.appendChild(croppedCanvas);
        },
    });

    // Xử lý sự kiện khi tải ảnh lên
    imageInput.addEventListener('change', function (e) {
        var file = e.target.files[0];
        var reader = new FileReader();

        reader.onload = function (event) {
            // Set ảnh vào CropperJS
            cropper.replace(event.target.result);
        };

        reader.readAsDataURL(file);
    });
});

But when i finish crop and download, i can’t show the image. This error: Photo can’t open this file because the format is curently unsupported or the file is corrupted. I don’t know why

Pls help me fix …

Nginx Sever with local printers on window

I have deployed my Laravel App to AWS and using NGINX server. I want to print some receipts from server to the local printers. I am using this package mike42/escpos-php.
and here is my code

try {
        $connector = new Mike42EscposPrintConnectorsWindowsPrintConnector("POS-80C");

        /* Print a "Hello world" receipt" */
        $printer = new Mike42EscposPrinter($connector);
        $printer -> text("Hello World!n");
        $printer -> cut();

        /* Close printer */
        $printer -> close();
    } catch (Exception $e) {
        echo "Couldn't print to this printer: " . $e -> getMessage() . "n";
    }```

I have enabled sharing of this printer *POS-80C* from windows. 

But whenever I try to print, I rceived this error.

Command "smbclient '//ip-172-31-43-229/POS-80C' -c 'print -' -N -m SMB2" failed with exit code 1: do_connect: Connection to ip-172-31-43-229 failed (Error NT_STATUS_CONNECTION_REFUSED)

Here *ip-172-31-43-229* is IP of server on AWS.


*smbclient* is working fine on nginx. What can be the issue?