cUrl don’t sync when cookie in header is big

    $cookies_str = '';
    for ($i=0; $i < 1000; $i++) { 
        $cookies_str .= "test{$i}=testtestestestsetse{$i}; ";
    }
    $param = [
        //set params here
    ];
    $param = http_build_query($param);
    ///
    $url = "http://localhost/get_test.php";
    $cUrl = curl_init($url);
    curl_setopt($cUrl, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($cUrl, CURLOPT_POSTFIELDS, $param);
    curl_setopt($cUrl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($cUrl, CURLOPT_TIMEOUT, 5);
    curl_setopt($cUrl, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($cUrl, CURLOPT_HTTPHEADER, [
        'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
        'Content-Length: ' . strlen($param)
    ]);
    curl_setopt($cUrl, CURLOPT_COOKIE, $cookies_str);
    //execute post
    $data = curl_exec($cUrl);
    //close connection
    curl_close($cUrl);

When I set $i=10, curl_exec will do sync. But when I set $i=1000, curl_exec will do async (not sync).

How to force curl_exec always do sync ?

Please help ! Thank you for advanced.

How to download file using PHP & JavsScript

How can I use PHP to download a file from server or third party URL.

Also I want the exact event when the file is completely downloaded. So want to call some custom JS on that event.

Tried with pure JavaScript

I tried below snippet, but got blocked access error.

Access to fetch at ‘https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf’ from origin ‘http://localhost/test.php’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

JS Code below

let fileurl = 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf';
  fetch(fileurl)
  .then(resp => resp.blob())
  .then(blob => {
    const url = window.URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.style.display = 'none';
    a.href = url;
    // the filename you want
    a.download = fileurl;
    document.body.appendChild(a);
    a.click();
    window.URL.revokeObjectURL(url);
    alert('your file has downloaded!'); // or you know, something with better UX...
  })
  .catch(() => alert('oh no!'));

Tried with PHP + Ajax

In this case I noticed if I call this file with browser then it’s now able to download file.
But here I cannot get the actual download complete event.
Also when I have called the PHP url using AJAX then got encoded string like below.

%PDF-1.7
%����
1 0 obj
<</Type/Catalog/Pages 2 0 R/Lang(en-GB) /StructTreeRoot 291 0 R/Outlines 285 0 R/MarkInfo<</Marked true>>/Metadata 672 0 R/ViewerPreferences 673 0 R>>
endobj
2 0 obj

PHP Code below

$url = 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf';
$filename = basename($url);
$filetype = filetype($url);
header('Content-Disposition: attachment; filename=' . $filename);
header("Content-type: " . $filetype); // act as image with right MIME type
ob_clean();
flush();
readfile($url);

Please suggest what are the best possibility to achieve this. With no complex things. Also should work with all native browsers and devices.

Installation of php8.1 with a Docker

I’m trying to install php8.1 and composer with a dockerfile but it returns some errors of unfound packages. What I have to do to solve my problem?

[****@#### picture-this-web]$ docker build -t picturethis:0.2 .
Sending build context to Docker daemon  4.291MB
Step 1/13 : FROM php:8.1 as php-builder
 ---> 5478436e6090
Step 2/13 : RUN apt-get update && apt-get install -y     curl unzip php8.1 php8.1-cli php8.1-mbstring php8.1-xml php8.1-zip php8.1-json php8.1-curl
 ---> Running in 49d1b6f54b44
Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
Get:4 http://deb.debian.org/debian bullseye/main amd64 Packages [8183 kB]
Get:5 http://deb.debian.org/debian-security bullseye-security/main amd64 Packages [237 kB]
Get:6 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [14.6 kB]
Fetched 8643 kB in 1s (6084 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package php8.1
E: Couldn't find any package by glob 'php8.1'
E: Couldn't find any package by regex 'php8.1'
E: Unable to locate package php8.1-cli
E: Couldn't find any package by glob 'php8.1-cli'
E: Couldn't find any package by regex 'php8.1-cli'
E: Unable to locate package php8.1-mbstring
E: Couldn't find any package by glob 'php8.1-mbstring'
E: Couldn't find any package by regex 'php8.1-mbstring'
E: Unable to locate package php8.1-xml
E: Couldn't find any package by glob 'php8.1-xml'
E: Couldn't find any package by regex 'php8.1-xml'
E: Unable to locate package php8.1-zip
E: Couldn't find any package by glob 'php8.1-zip'
E: Couldn't find any package by regex 'php8.1-zip'
E: Unable to locate package php8.1-json
E: Couldn't find any package by glob 'php8.1-json'
E: Couldn't find any package by regex 'php8.1-json'
E: Unable to locate package php8.1-curl
E: Couldn't find any package by glob 'php8.1-curl'
E: Couldn't find any package by regex 'php8.1-curl'
The command '/bin/sh -c apt-get update && apt-get install -y     curl unzip php8.1 php8.1-cli php8.1-mbstring php8.1-xml php8.1-zip php8.1-json php8.1-curl' returned a non-zero code: 100

Here is my dockerfile:

# PHP app

FROM php:8.1 as php-builder

# Actualizar el sistema e instalar las dependencias necesarias

RUN apt-get update && apt-get install -y
curl unzip php8.1 php8.1-cli php8.1-mbstring php8.1-xml php8.1-zip php8.1-json php8.1-curl

# Instalar Composer

RUN curl -sS https://getcomposer.org/installer | php — –install-dir=/usr/local/bin –filename=composer

# Install dependencies file

COPY composer*.json ./

# Install dependencies

RUN composer install

# ——————————————————–

# Node app with npm dependencies

FROM node:18.11.0-slim

COPY –from=php-builder /app /usr/src/app

# Create app directory

WORKDIR /usr/src/app

# Install app dependencies

COPY package*.json ./

# Install dependencies

RUN npm install

# Bundle app source

COPY . .

EXPOSE 5173

CMD [ “npm”, “run”, “build” ]

What is the recommended framework and/or model to use for providing direct and appropriate feedback for self-help and therapeutic exercises?(PHP)

You are looking for a recommendation for a framework and/or model to use in an existing project (PHP).
The purpose of the framework/model is to provide direct and appropriate feedback for self-help and therapeutic exercises and questionnaires.
You are seeking advice on which framework/model would be best suited for this purpose.
I thought it would be easier to integrate AI in a project. It is for my
graduation assignment as a software developer (PHP)

Apply several conditions when uploading an avatar image

I had a problem when uploading the avatar image, which I fixed: link

Now I want some conditions to apply when uploading an avatar image, In the one user avatar plugin settings, I ticked the avatar image size change and set its size to 32×32.

  1. Only allow uploading avatar images that are equal in width and length, exp : 300×300, 1000×1000
  2. When the avatar image is uploaded, it will remove the original size and replace it with a scaled 32×32 size. I want to keep the original size, actually the avatar image has 2 sizes : original and 32×32
  3. When the avatar image is changed, all 2 sizes are removed and the avatar image is replaced with the original 2 sizes and 32×32.

This is my code :

function customize_wpua_action_process_option_update( $user_id ) {

    global  $blog_id,
            $post,
            $wpdb,
            $wp_user_avatar,
            $wpua_force_file_uploader,
            $wpua_resize_crop,
            $wpua_resize_h,
            $wpua_resize_upload,
            $wpua_resize_w,
            $wpua_admin;

    // Check if user has publish_posts capability
    if ( $wp_user_avatar->wpua_is_author_or_above() && ! $wpua_force_file_uploader ) {
        $wpua_id = isset( $_POST['wp-user-avatar'] ) ? absint( $_POST['wp-user-avatar'] ) : 0;

        // Remove old attachment postmeta
        delete_metadata( 'post', null, '_wp_attachment_wp_user_avatar', $user_id, true );

        // Create new attachment postmeta
        add_post_meta( $wpua_id, '_wp_attachment_wp_user_avatar', $user_id );

        // Update usermeta
        update_user_meta( $user_id, $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar', $wpua_id );
    } else {
        // Remove attachment info if avatar is blank
        if ( isset( $_POST['wp-user-avatar'] ) && empty( $_POST['wp-user-avatar'] ) ) {
            // Delete other uploads by user
            $q = array(
                'author'         => $user_id,
                'post_type'      => 'attachment',
                'post_status'    => 'inherit',
                'posts_per_page' => '-1',
                'meta_query'     => array(
                    array(
                        'key'     => '_wp_attachment_wp_user_avatar',
                        'value'   => "",
                        'compare' => '!='
                    ),
                ),
            );

            $avatars_wp_query = new WP_Query( $q );

            while( $avatars_wp_query->have_posts() ) {
                $avatars_wp_query->the_post();

                wp_delete_attachment( $post->ID );
            }

            wp_reset_query();

            // Remove attachment postmeta
            delete_metadata( 'post', null, '_wp_attachment_wp_user_avatar', $user_id, true );

            // Remove usermeta
            update_user_meta( $user_id, $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar', '' );
        }

        // Create attachment from upload
        if ( ! empty( $_FILES['wpua-file'] ) ) {
            $file = $_FILES['wpua-file'];
            $name = isset( $file['name'] ) ? sanitize_file_name( $file['name'] ) : '';
            $type = isset( $file['type'] ) ? sanitize_mime_type( $file['type'] ) : '';
            $file = wp_handle_upload( $file, array(
                'test_form' => false,
            ) );

            if ( isset( $file['url'] ) ) {
                if ( ! empty( $type ) && preg_match( '/(jpe?g|gif|png)$/i' , $type ) ) {
                    // Resize uploaded image
                    if ( 1 == (bool) $wpua_resize_upload ) {
                        // Original image
                        $uploaded_image = wp_get_image_editor( $file['file'] );

                        // Check for errors
                        if ( ! is_wp_error( $uploaded_image ) ) {
                            // Resize image
                            $uploaded_image->resize( $wpua_resize_w, $wpua_resize_h, $wpua_resize_crop );

                            // Save image
                            $uploaded_image->save( $file['filee'] );
                        }
                    }

                    // Break out file info
                    $name_parts = pathinfo( $name );
                    $name       = trim( substr( $name, 0, -( 1 + strlen( $name_parts['extension'] ) ) ) );
                    $url        = $file['url'];
                    $file       = $file['file'];
                    $title      = $name;

                    // Use image exif/iptc data for title if possible
                    if ( $image_meta = @wp_read_image_metadata( $file ) ) {
                        if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) {
                            $title = $image_meta['title'];
                        }
                    }

                    // Construct the attachment array
                    $attachment = array(
                        'guid'           => $url,
                        'post_mime_type' => $type,
                        'post_title'     => $title,
                        'post_content'   => '',
                    );

                    // This should never be set as it would then overwrite an existing attachment
                    if ( isset( $attachment['ID'] ) ) {
                        unset( $attachment['ID'] );
                    }

                    // Save the attachment metadata
                    $attachment_id = wp_insert_attachment( $attachment, $file );

                    if ( ! is_wp_error( $attachment_id ) ) {
                        // Delete other uploads by user
                        $q = array(
                            'author'         => $user_id,
                            'post_type'      => 'attachment',
                            'post_status'    => 'inherit',
                            'posts_per_page' => '-1',
                            'meta_query'     => array(
                                array(
                                    'key'     => '_wp_attachment_wp_user_avatar',
                                    'value'   => '',
                                    'compare' => '!=',
                                ),
                            ),
                        );

                        $avatars_wp_query = new WP_Query( $q );

                        while ( $avatars_wp_query->have_posts() ){
                            $avatars_wp_query->the_post();

                            wp_delete_attachment($post->ID);
                        }

                        wp_reset_query();

                        wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );

                        // Remove old attachment postmeta
                        delete_metadata( 'post', null, '_wp_attachment_wp_user_avatar', $user_id, true );

                        // Create new attachment postmeta
                        update_post_meta( $attachment_id, '_wp_attachment_wp_user_avatar', $user_id );

                        // Update usermeta
                        update_user_meta( $user_id, $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar', $attachment_id );
                    }
                }
            }
        }
    }
} add_action( 'woocommerce_save_account_details', 'customize_wpua_action_process_option_update' );

How to Display from my Database Randomly using PHP & MySql

I am trying to display my database result randomly as user visit page or refresh see my code below

            $result = $food->itemsList();
            $count=0;
            while ($item = $result->fetch_assoc()) { 
            if ($count == 0) {
                echo "<div class='row'>";
            }
            ?>  
                
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 mb-3 food-item">
                    <form method="post" action="cart.php?action=add&id=<?php echo $item["id"]; ?>">
                    <input type="hidden" name="status" value="<?php echo $item["status"]; ?>">
                        <input type="hidden" name="item_name" value="<?php echo $item["name"]; ?>">
                        <input type="hidden" name="item_price" value="<?php echo $item["price"]; ?>">
                        <input type="hidden" name="description" value="<?php echo $item["description"]; ?>">
                        <input type="hidden" name="item_id" value="<?php echo $item["id"]; ?>">
                        <input type="hidden" name="vendor_name" value="<?php echo $item["vendor_name"]; ?>">
                        <input type="hidden" name="vendor_address" value="<?php echo $item["vendor_address"]; ?>">
                        <input type="hidden" name="images" value="<?php echo $item["images"]; ?>">

                        <div class="card rounded-0" align="center"; style="background-color:#0a386e;">

                        

                            <div class="food-img-holder position-relative overflow-hidden" style="z-index:1;">
                            <img src="<?php echo $item["images"]; ?>" class="img-top">
                            </div> 

Thanks I appreciate your help.

Flutter Conversion From JAVA

I have an android mobile app source code which is integrated with REST API. The backend (i.e.,base URL, Admin Panel) is written in PHP and Android code(UI Part) is written in JAVA and integrated with API PHP Code. Now i want to change the JAVA part to Dart code and integrate it with the existing REST API for the Android App. Or is there any other better ideas.

Purpose is I’m not familiar with JAVA for building Android Project. So needing it in Dart to work in Flutter. Thanks in advance.

Tried to convert to Kotlin in Android Studio. It’s not helping.

In My Php File, Only The Include Part Is Visible In Browser And Html Code Is Not Working Or Displaying

<?php

include('C:xampphtdocsadminincludesheader.php');

include('C:xampphtdocsadminincludesnavbar.php');

include('C:xampphtdocsadminincludessidebar.php');

?>

<!-- Content Wrapper. Contains page content -->

<div class="content-wrapper">

<!-- Content Header (Page header) --> <div class="content-header">

<div class="container-fluid">

<div class="row mb-2">

<div class="col-sm-6">

<h1 class="m-0 text-dark">Dashboard</h1>

</div><!--/.col --> <div class="col-sm-6">

<ol class="breadcrumb float-sm-right">

<li class="breadcrumb-item"><a href="#">Home</a></li>

<li class="breadcrumb-item active">Dashboard vi</li>

</ol>

</div><!--/.col --> </div><!--/.row -->

</div><!--/.container-fluid -->

</div>



<?php include('C:xampphtdocsadminincludesfooter.php");
?>

 

    <?php

include('C:xampphtdocsadminincludesheader.php');

include('C:xampphtdocsadminincludesnavbar.php');

include('C:xampphtdocsadminincludessidebar.php');

?>

<!-- Content Wrapper. Contains page content -->

<div class="content-wrapper">

<!-- Content Header (Page header) --> <div class="content-header">

<div class="container-fluid">

<div class="row mb-2">

<div class="col-sm-6">

<h1 class="m-0 text-dark">Dashboard</h1>

</div><!--/.col --> <div class="col-sm-6">

<ol class="breadcrumb float-sm-right">

<li class="breadcrumb-item"><a href="#">Home</a></li>

<li class="breadcrumb-item active">Dashboard vi</li>

</ol>

</div><!--/.col --> </div><!--/.row -->

</div><!--/.container-fluid -->

</div>



<?php include('C:xampphtdocsadminincludesfooter.php");
?>

Only the include part displays in browser but html part doesn’t display

Still I didn’t find any solution

woocommerce discount cart withouth using add_fee method

The problem:

i want dynamically reprice the cart without repricing the articles to offer the customers one or more discounts.

i also asked chatgpt, but the solutions were not great, and I got the tip using the add_fee method.

Here are 3 solutions i found and the side effects:

1.: Some solutions I found work only over the article price
prob: the user don’t see that he have pay less

2.: add_fee Method with a negative number
prob: not recommend by Woo and case vat problems

3.: create a article with a negative value
prob: don’t work with percent and if the discount is bigger than the cart there’s also vat problems

How change $_SESSION[‘user’] = $email to Welcome username [closed]

I would like to make a change so that $_SESSION[‘user’] = $email changes to WELCOME user’s name instead of the email address the user logs in with.

if (isset($_POST["login"])) {
    $email = $_POST["email"];
    $password = $_POST["password"];
    require_once "database.php";
    $sql = "SELECT * FROM users WHERE email = '$email'";
    $result = mysqli_query($conn, $sql);
    $user = mysqli_fetch_array($result, MYSQLI_ASSOC);
    if ($user) {
        if (password_verify($password, $user["password"])) {
            session_start();
            $_SESSION['user'] = $email;
            
            header("Location: index.php");

esc_sql breaks line return escaping

I need to create a new post based on data from an RSS file.

First, I normalize line breaks sequences based on OS type for post content:
$post_content = str_replace(array ("rn", "n", "r"), PHP_EOL, $post_content);

To prepare resulting text for inserting to the database I use the WordPress function esc_sql:
post_content = str_replace( array( '<![CDATA[', ']]>'), '', esc_sql( trim( $post_content[1] ) ) );

But, it removes char escaping “” for all line break sequences.

So, instead of this text:

Line 1
Line 2

I got this: (line breaking “n” sequencing replaced by “n” letter):

Line 1.nLine2.

I found only this solution: replace PHP_EOL with <br /> tag but I’m not sure it’s the best option:
$post_content = str_replace(array ("rn", "n", "r"), "<br />", $post_content);

Maybe there is some alternative for esc_sql function?

Mail not send in php [duplicate]

hello i make the app in shopify.in contact_us form click send Email to customer.this same code i put in second app it will be run properly but same code i applying on this App than not send the mail.and this files i upload in .in ftp server and the Email successfully send those app i upload in .org ftp server. idont know this is occuring bcoz of server or not! please help me this is my code.

include_once("includes/mysql_connect.php");
include_once("includes/shopify.php");
include_once("includes/check_token.php");



$my = $shopify->rest_api('/admin/api/2023-01/shop.json', $array, 'GET');
$data = json_decode($my['body'], true);

$email = $data['shop']['email'];

$shop_owner = $data['shop']['shop_owner'];
$shop = $_GET['shop'];


if (isset($_POST['submit'])) {
    $user_name = $_POST['user_name'];
    $user_email = $_POST['user_email'];
    $user_subject = $_POST['user_subject'];
    $stor_pswd = $_POST['user_Password'];
    $page_info = $_POST['page_info'];
    $user_content = $_POST['messege'];

    $sql = "INSERT INTO `googlereview_contact`(`user_name`,`user_email`,`user_subject`,`store_pswd`,`page_info`,`user_content`,`shop`,`created_at`) values
    ('" . $user_name . "','" . $user_email . "','" . $user_subject . "','" . $stor_pswd . "','" . $page_info . "','" . $user_content . "','" . $shop . "',NOW())  ON DUPLICATE KEY UPDATE 
    shop='" . $shop . "',user_name='" . $user_name . "',user_email='" . $user_email . "',user_subject='" . $user_subject . "',store_pswd='" . $stor_pswd . "',page_info='" . $page_info . "',user_content='" . $user_content . "'";
    // echo $sql;  
    if (!mysqli_query($conn, $sql)) {
    } else {
        echo '<div class="alert alert-success" style="position: absolute;top: 57px;width: 100%;" role="alert" id="div3">
  Email Send Successfully. 
 </div>';
        $msg = "Name:$user_name;nEmail:$user_email;nSubject:$user_subject;nStore Password:$stor_pswd;nPage Information:$page_info;nMessege:$user_content;";
        $msg = wordwrap($msg, 80);
        mail("[email protected]",$user_subject,$msg);
       
        
       
    }
}


in the static file i dont do any other code then the email not send at time

PHP Error using form Extension with Variants in TYPO3 11

i use the form extension (form) with variants and multiple steps for a contact form.
variants hide or show steps depending on the value of checkboxes or dropdowns.

the form works as expected but causes php-errors in the logs when i use php 8 or 8.1:

Core: Error handler (FE): PHP Warning: Undefined array key "singleselect-3-1-1" in /html/typo3/typo3_src-11.5.26/vendor/symfony/expression-language/Node/GetAttrNode.php line 97

in this case “singleselect-3-1-1” is the identifier of the field type: SingleSelect which is used as variant in the next step

TYPO3 11.5.26
form 11.5.26
PHP Version 8.0.26 or 8.1.13

Can anybody confirm this problem in TYPO3?
If yes, how can i submit this bug to the TYPO3 core team?
If no, i have to contact my hoster for a php problem?

Thanks for any feedback

Can’t update value in multi dimensional array

I have an array as below. I wish to update the value of [form_id] => 79 to [form_id] => 123.

Array
(
    [directory_table-columns] => Array
        (
            [6433fed3e408d] => Array
                (
                    [id] => 20
                    [label] => Rank
                    [form_id] => 79
                )
            [6433ffa1bf847] => Array
                (
                    [content] => <a href="{site_url}/user/{Player:1}">{Player:1}</a>
                    [label] => Custom Content
                    [form_id] => 79
                )
...
...

Below is my code.

foreach ( $src_gravityview_directory_fields as $key1 => $value1 ) {
        foreach ( $value1 as $key2 => &$value2 ) {
            $value2['form_id'] = $dest_form_id;
        }           
}

But the value of form_id doesn’t change. I also tried the below but no joy.

foreach ( $src_gravityview_directory_fields as $key1 => $value1 ) {

    foreach ( $value1 as $key2 => $value2 ) {
        
        $value2[$key2]['form_id'] = $dest_form_id;
    }           

}

I tried this but it caused an infinite loop.