UNPROCESSABLE_ENTITY error with AUTH_FLOW_REQUIRED [closed]

We are using paypal v1 APIs, which were running fine, but from yesterday we are getting below error while trying to send invoice –

https://api.paypal.com/v1/invoicing/invoices/INV2-myInvoiceId/send. 
{
    "name": "UNPROCESSABLE_ENTITY",
    "message": "The requested action cannot be performed, and may require interaction with APIs or processes outside of the current request",
    "debug_id": "3924abcd068",
    "details": [
        {
            "field": "step_up_context",
            "value": "82f2f19af898abcdefgh95a",
            "issue": "AUTH_FLOW_REQUIRED"
        }
    ],
    "links": [
        {
            "href": "https://developer.paypal.com/docs/api/invoicing/#errors",
            "method": "GET"
        }
    ]
}

Here I am not able to understand, why it is giving error, I tried to google about ‘AUTH_FLOW_REQUIRED’ but didn’t found anything specific.
Please help me to solve it.

Using substr_replace inside a nested loop almost works but duplicates the haystack what am I missing?

I’m an amateur web programmer. From time to time I like to build something for personal use, taking a lot of pleasure from the result when a script finally does what I want it to do. So I learn as I go, but now I’m stuck and I hope someone here would be willing to take a look at what I’m doing.

I’m working on a project that takes text files from a folder and searches the text of each file for specific keywords that correspond to image files that I’m trying to insert in the text as an html image tag using php. I got it almost working: the correct images get inserted at the desired points, and text files that do not contain a keyword remain untouched, but the text files that have images inserted are doubled: one text file with added image and one original text file. I have tried different approaches but either it doesn’t work at all, or the text files with inserted images are duplicated.

Where lies the foult? Am I going at it the wrong way?

Here is my code:

<?php
$path = // array of .txt-filenames with plain tekst
$imagepath = // array of .jpg-filenames

foreach ($path as $file) {

$haystack = file_get_contents("$file");

    foreach ($imagepath as $imagefile) {
        $needle = $imagefile;
        $position = strpos($haystack,$needle);

        if ($position !== false) {$output = substr_replace($haystack, "<img src='$imagefile'>", $position, 0);} else {$output = $haystack;}
              
        echo $output; }

}
?>

Why I get Syntax error when I prepare statement for dropping a Db? [duplicate]

In my code I try to drop a database:

  $connectionString="mysql://...";
  $pdo = new PDO($connectionString);

  ...

  // I intentionally Drop the Db from the user-given db name
  // Details ommited for simplicity
  $testDbName=$_POST['db_name'];
  $stmt = $pdo->prepare("DROP DATABASE :db");
  $stmt->bindValue(":db", $testDbName);
  $stmt->execute();

But I get the following error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''test_php_app_1076'' at line 1.ESQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''test_php_app_1076'' at line 1

But if I try this:

  $pdo->query("DROP DATABASE `" . str_replace('`', '``', $testDbName) . "`");

Seem to work fine. Is there a way to make it work using prepared statements?

Dusk tests fail to trigger onbeforeunload event in Laravel 11 / Dusk 8

I’ve encountered an issue with Laravel Dusk tests not triggering the onbeforeunload event when navigating away from a page. This behavior differs from what I observe when manually interacting with the page in a browser.

Steps To Reproduce

Create a route that returns an HTML page with an onbeforeunload event handler:

Route::get('/leave', function () {
    return '<!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Page</title>
    </head>
    <body>
        <h1 id="head">Test page</h1>
        <a href="/">page</a>

        <script>
            window.onbeforeunload = function(e) {
                e = e || window.event;

                if (e) {
                    e.returnValue = "Go?";
                }

                return "Go?";
            };
        </script>
    </body>
    </html>';
});

Create a Dusk test that visits this page:

phpCopypublic function testLeave(): void
{
    $this->browse(function (Browser $browser) {
        $browser->visit('/leave')
            ->pause(15000);
    });
}

Run the Dusk test.

Expected behavior:
When the test navigates away from the page (either by clicking the link or using Dusk’s navigation methods), it should trigger the onbeforeunload event and show a confirmation dialog.

Actual behavior:
The onbeforeunload event is not triggered, and no confirmation dialog is shown when the test navigates away from the page. This occurs both when clicking the link programmatically and when using Dusk’s built-in navigation methods.

Additional information:
This issue was not present in Laravel 10 with Dusk 7, where the test successfully triggered the onbeforeunload event.
The onbeforeunload event works as expected when manually interacting with the page in a browser.
For manual verification, I removed the –headless=new parameter in the DuskTestCase.php file to observe the browser behavior directly.

Could you please investigate this issue and provide guidance on how to properly test onbeforeunload events in Laravel 11 with Dusk?

Dusk Version: 8.2.6
Laravel Version: 11.25
PHP Version: 8.3.3
PHPUnit Version: 11.3.6

PHP parse error on Laravel `syntax error, unexpected token “”` public/index.php :17

After a fresh installation of Laravel with “LivewireVolt” I create “/resources/views/livewire/nom/products-list.blade.php” for listing “Products”, but when try to go to the address I receive an “Internal Server Error” message

I have a new Laravel 11 installation with Breeze and Volt packages

“/resources/views/livewire/nom/products-list.blade.php”

<?php

use LivewireVoltComponent;
use LivewireAttributes{Layout, Title};
use IlluminateSupportFacadesRedirect;
use IlluminateSupportFacadesDB;
use LivewireWithPagination;

use AppModelsProduct;

new 
#[Layout('layouts.app')]
#[Title('Продукти')]
class extends Component {
    //
    public string $search = '';

    public function addNom() {
        return Redirect::to('nom/product.edit/'.'0');
    }

    public function editNom($id)
    {
        return Redirect::to('nom/product.edit/'.(string) $id);
    }

    public function with(): array {
        $stext = $this->search;
        $noms = Product::query()
            ->where(function ($qname) use ($stext) {
                if($stext != '') { 
                    $stext = '%'.$stext.'%';
                    $qname->where('name','LIKE',$stext); 
                }
            })
            ->orderBy('name')
            ->paginate(10)
        ;
        return [
            'noms' => $noms,
        ];
    }

}; ?>

<div>
    <x-slot name="header">
        <h2 class="text-xl font-semibold leading-tight text-gray-800">
            {{ __('Продукти') }}
        </h2>
    </x-slot>

    <div class="py-2">
        <div class="mx-auto max-w-7xl sm:px-6 lg:px-8">
            <x-flash-message />

            <div class="grid grid-cols-3 gap-4 mt-4 mb-2">
                <table>
                    <tr>
                        <td>
                            <x-button wire:click="addNom" class="w-2/3 col-span-1 h-11" >{{ __('Нов') }}</x-button>
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <!-- Search -->
                            <div class="col-span-1">
                                <x-label for="search" value="{{ __(':') }}" />
                                <x-input.search
                                    wire:model.live="search"
                                    class="block w-full py-2 pl-12 pr-5 mt-4 text-lg"
                                    placeholder="Търси..."
                                    autocomplete="off"
                                />
                            </div>
                        </td>

                    </tr>

                </table>

            </div>

            <x-table>
                <x-slot name="head">
                    <tr>
                        <th scope="col" class="px-3 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
                            Name
                        </th>
                        <th scope="col" class="px-3 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
                            Code
                        </th>
                        <th scope="col" class="px-3 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
                            ME
                        </th>
                        <th scope="col" class="px-1 py-3 text-xs font-medium tracking-wider text-center text-gray-500 uppercase">
                            Edit
                        </th>
                    </tr>

                </x-slot>

                <x-slot name="body">
                    @foreach ($noms as $key => $nom)
                        <tr>
                            <td class="py-1">
                                <div class="flex items-center">
                                    <div class="ml-4">
                                        <div class="text-xs font-medium text-gray-900">
                                            {{ $nom?->name }}
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="py-1">
                                <div class="flex items-center">
                                    <div class="ml-4">
                                        <div class="text-xs font-medium text-gray-900">
                                            {{ $nom?->code }}
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="py-1">
                                <div class="flex items-center">
                                    <div class="ml-4">
                                        <div class="text-xs font-medium text-gray-900">
                                            {{ $nom?->me }}
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class="px-1 py-4 text-xs font-medium text-center">
                                <button
                                    wire:click="editNom({{ $nom?->id }})"
                                    title="Edit"
                                    class="inline-flex items-center px-4 py-2 font-bold bg-yellow-400 rounded hover:bg-grey text-grey-darkest"
                                >
                                    <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
                                    </svg>
                                </button>
                            </td>

                        </tr>
                    @endforeach
                </x-slot>

                {{ $noms->links() }}
            </x-table>

        </div>
    </div>
</div>

web.php

Volt::route('nom/products.list', 'nom/products-list')->name('nom/products.list');

resources/views/layouts/app.blade.php

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="csrf-token" content="{{ csrf_token() }}">

        <title>{{ config('app.name', 'Laravel') }}</title>

        <!-- Fonts -->
        <link rel="preconnect" href="https://fonts.bunny.net">
        <link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />

    @livewireStyles

        <!-- Scripts -->
        @vite(['resources/css/app.css', 'resources/js/app.js'])
    </head>
    <body class="font-sans antialiased">
        <div class="min-h-screen bg-gray-100">
            <livewire:layout.navigation />

            <!-- Page Heading -->
            @if (isset($header))
                <header class="bg-white shadow">
                    <div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
                        {{ $header }}
                    </div>
                </header>
            @endif

            <!-- Page Content -->
            <main>
                {{ $slot }}
            </main>
        </div>

    @livewireScripts
    </body>
</html>

How to create environment variables with the the package vlucas/phpdotenv for yii2 advance template

I installed the package:

composer require vlucas/phpdotenv

and in the root of my project i have a .env file with some configuration variable.

Now i try to use PHP dotenv to get the ENV variable availables to the prod and dev environments.
So, to do this, i’ve modified the yii file inside of environments/dev and environments/prod folders in order to get env variables available inside the project.
So the yii file is :

#!/usr/bin/env php
<?php
/**
 * Yii console bootstrap file.
 */
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/vendor/yiisoft/yii2/Yii.php';
require __DIR__ . '/common/config/bootstrap.php';
require __DIR__ . '/console/config/bootstrap.php';

$dotenv = DotenvDotenv::createImmutable(__DIR__ . '/');
$dotenv->load();

$config = yiihelpersArrayHelper::merge(
    require __DIR__ . '/common/config/main.php',
    require __DIR__ . '/common/config/main-local.php',
    require __DIR__ . '/console/config/main.php',
    require __DIR__ . '/console/config/main-local.php'
);

$application = new yiiconsoleApplication($config);
$exitCode = $application->run();
exit($exitCode);

For example i modified my main-local.php inside environmentscommon folder

'db' => [
            'class' => yiidbConnection::class,
            'dsn' => 'mysql:host=localhost;dbname='.$_ENV['DB_NAME'],
            'username' => $_ENV['DB_USER'],
            'password' => $_ENV['DB_PASSWORD'],
            'charset' => 'utf8',
            'enableSchemaCache' => $_ENV['DB_USE_CACHE'],
            'schemaCacheDuration' => 3600,
            'schemaCache' => 'cache',
        ],

But when i run php init $_ENV variable is empty. Is this the correct way to set .env file? what am I doing wrong?

This is my .env file

# APPLICATION CONFIG
APP_NAME="Yii -CMS"
APP_LANGUAGE=it
APP_CHARSET=utf-8
APP_ENV=dev # [dev | test | prod]
APP_DEBUG=true # use 'false' in production

# DATABASE CONFIG
DB_HOST=localhost
DB_CONNECTION=mysql
DB_PORT=3306
DB_USER=root
DB_PASSWORD=''
DB_NAME=yiicms
DB_USE_CACHE=false # use 'true' in production

calculating numbers not showing all decimal numbers [duplicate]

I want to know if the PHP has a limit on showing decimal numbers or Do I need to configure something in the PHP config.
I having a project calculating measurement

This is only sample value I used.
In PHP when I calculate this formula.

53 cm / 2.54 inch = 20.866141732283

vice versa

20.866141732283 * 2.54 inc = 52.999999999999

The result is not 53 when I calculate back to cm because It has a missing decimal number. If I calculate it by using the calculator. This is the result

53cm / 2.54 inch = 20.866141732283465

last part 465 is missing in the PHP calculation.

This happened to any number I used.

How to enable “include credentials” in PHP curl request?

I have successfully executed fetch request from the javascript code below

await fetch("api-path", {
    method: "POST",
    headers: { "Content-Type": "application/json; charset=UTF-8" },
    body: JSON.stringify({ key01: "value01",  key02: "value02" }),
    credentials: "include"
})
.then (async (res) => {
    const jRes = await res.json();
    return jRes;
});

I want to make a similar request using php curl, however, not sure how to send credentials: “include” parameter with the php curl request ! Can some one guide for the same?

I have put the following code in PHP file, along with curl request, but it did not help:

header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Credentials: true');

Why email not sending through HTML site using php? [duplicate]

I am trying to send emails through my HTML site using PHP, but unfortunately, it is not working.
What is the actual problem? Please can anybody help?>

This is my HTML code:

<form action="contact.php" method="POST">
<input class="form-control form-control-lg" name="name" id="name" type="text" placeholder="Your Name*" required aria-label=".form-control-lg example">
<input class="form-control form-control-lg" name="phone" id="phone" type="number" placeholder="Your Phone No" aria-label=".form-control-lg example">
<input class="form-control form-control-lg" name="email" id="email" type="email" placeholder="Your Email*" required aria-label=".form-control-lg example">
<textarea class="form-control pt-4" name="message" id="message" placeholder="Your Message" rows="3"></textarea>
<div class="btn_group">
    <button type="submit" class="btn olive">Send Mail</button>  
</div>

and my PHP code:

<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
$formcontent="From: $name n Message: $message n Phone: $phone";
$recipient = "[email protected]";
$mailheader = "From: $email rn";
mail($recipient, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";

?>

How to set a dynamic range by fixed number

I am trying to set a range by a fixed number for an example.

$fixed = 5;
$value = 7;

So if my value is 7 it will be in a range from 5 to 10

I was trying the old fashion method to add + 5 to the value, but it goes out of the range. (7 + 5 = 12) and it has to be in range between 5 to 10.

$value = 19; // range in 15 to 20
$value = 23; // range in 20 to 25

Any idea?

How to remove dot(.) comma (,) from name

I am trying to make a URL from a user name but I have some problems doing so. Here are some examples of what I am trying to do:

User Name = J.R.R. Tolkien
I want To convert Like THis = j-r-r-tolkien


User Name = Barrie M. Osborne
Convert = barrie-m-osborne

User Name = William Broyles Jr.
Convert = william-broyles-jr


User Name Comma (,) = Harry Waters, Jr.
Convert = harry-waters-jr

This is my code:

'name_slug' => strtolower(str_replace('.', '', str_replace(' ', '-', empty($name) ? '' : $name))),

This just doesn’t work for all cases. Can anyone help?

Using fpdf library creates a blank page

I get a blank page in the pdf-document, when I output a greater amount of text. I use the fpdf library. The following code (test code) is working well. When I add the commantary code I get a blank page.
The code is embedded in a wordpress CMS.

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$fileIncPath=getcwd();
require_once("$fileIncPath/wp-content/fpdf/fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetAutoPageBreak(false);
$pdf->SetFont('Arial','',10, true);
$pdf->Text(40,50,'Hallo Test auf Seite 1!', 0, 1);
$pdf->SetFont('Arial','',10, true);
$pdf->Text(40,60,'Hallo Test auf Seite 1!', 0, 1);
$pdf->SetFont('Arial','',10, true);
$pdf->Text(40,70,'Hallo Test auf Seite 1!', 0, 1);
$pdf->SetFont('Arial','',10, true);
$pdf->Text(40,80,'Hallo Test auf Seite 1!', 0, 1);
$pdf->SetFont('Arial','',10, true);
$pdf->Text(40,90,'Hallo Test auf Seite 1!', 0, 1);
//$pdf->SetFont('Arial','',10, true);
//$pdf->Text(40,100,'Hallo Test auf Seite 1!', 0, 1);
$pdf->SetFont('Arial','',10, true);
$pdf->Text(40,190,'Hallo Test auf Seite 1!', 0, 1);
$pdf->Output('I', 'test.pdf');
?>

I tested the code in a local environment only with php. This worked. On the server in a wordpress environment it didn’t work.

API Call by PHP [duplicate]

Good morning,

i have small problem to echo a variable. Maybe you can help me. Thanks!
https://api.openligadb.de/index.html

/getmatchdata/matchid

This works:

<?php echo $match["team1"]["teamIconUrl"]; ?>

But i’m not able to get the matchresult.

<?php echo $match["matchResults"]["pointsTeam1"]; ?>



<?php


// Retrieve the data for the current matchday from the OpenLigaDB API
$url = sprintf("https://api.openligadb.de/getmatchdata/bl1", $current);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$output = curl_exec($ch);
 
if ($output === false) {
    die("Error when requesting the API: " . curl_error($ch));
}

curl_close($ch);

// Decoding the API response
$matches = json_decode($output, true);

if ($matches === null) {
    die("Error processing API response: " . json_last_error_msg());
}
?>