How to prevent HTMLPurifier from sanitizing the inline style attribute?

I’m using HTMLPurifier to sanitize HTML, but I want to prevent any changes to the inline style attribute. Specifically, I don’t want HTMLPurifier to modify or sanitize the values of the style attribute while purifying the HTML.

Here’s a sample code:

require_once 'ezyang/htmlpurifier/library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
$dirty_html = '<div style="background-color: rgb(240, 240, 240);"> How configure HTMLPurifier to prevent sanitize of Inline-style Attribute ? </div>';
// I want to prevent any change done by purify on style Attribute values
$clean_html = $purifier->purify($dirty_html);

// But in $clean_html div style value becomes: style="background-color:rgb(0,240,240);"
echo $clean_html;

enter image description here

How can I configure HTMLPurifier to skip sanitizing the style attribute ?

Google analytics not assigning to traffic acquisition

I’m facing a problem with custom events sent to Google Analytics. The main problem is that custom sent events are being assigned only to user acquisition and not to traffic acquisition.

I’m sending 2 custom events.

1st event starts the session:

{
    "client_id": "435384.2118427612",
    "events": [
        {
            "name": "session_start_test",
            "params": {
                "session_id": 1733217977,
                "source": "Test source",
                "medium": "cpc",
                "session_number": 1
            },
            "timestamp_micros": 1733217976999990
        }
    ]
}

2nd event send source data:

{
    "client_id": "435384.2118427612",
    "events": [
        {
            "name": "custom_event_test",
            "params": {
                "session_id": 1733217977,
                "engagement_time_msec": 100,
                "title": "Test title",
                "country": "Estonia",
                "source": "Test source",
                "medium": "cpc",
                "campaign": "test",
                "campaign_source": "Test source",
                "campaign_medium": "cpc",
                "session_number": 2
            },
            "timestamp_micros": 1733217977000000
        }
    ],
    "user_properties": {
        "country": {
            "value": "Estonia"
        }
    }
}

Both events are sent to GA and can be seen inside realtime reporting.

The problem that both of these events still assign source/medium to user acquisition instead of traffic acquisition. I’ve also tried to send utm_source and utm_medium, but that did not work out. Any ideas where is the problem?

I’m sending both events with PHP curl, using Google Measurement Protocol API.

PHP PDO_SQLSRV – INSERT permission was denied on the object (but it works in SSMS on same credentials) [closed]

I’m facing this issue:

Fatal error: Uncaught PDOException: SQLSTATE[42000]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The INSERT permission was denied on the object ‘xxxxxxxxxx’, database ‘xxxxxxxxxx’, schema ‘dbo’. in /home/….

Error would be pretty straightforward except that I use this SQL Server account in SQL Server Management studio and I can do inserts there without problems. Moreover, I log on SA account via same PHP code and it is the same – this is why I figure this is not really permissions problem on SQL Server. Am I wrong?

Is there a setting in PDO like read only maybe? Or in SQL Server: “allow PHP connections” – this are just guesses.

How to Install Xapian in PHP 7.0

We were using PHP 5.6 and installed Xapian 1.2.24. It was working fine.
We upgraded to PHP 7.0 and the Xapian is not working.

Any help?

We are getting the following error.

PHP Fatal error: UNHANDLED EXCEPTION! Error: Call to undefined function new_Database() in /usr/share/php/xapian.php:2100

delhivery api integration with laravel botble cms website

I’m trying to integrate the Delhivery API into my application, but I’m facing multiple issues. Here’s what I’ve attempted so far:

Webhook Integration: I followed Delhivery’s documentation for webhook integration, but it failed to establish a proper connection or trigger responses. I double-checked the URL and payload structure, but no luck.

Manual Integration: I tried using cURL and Postman for manual requests. The API returns a response, but it’s either inconsistent or gives errors like 401 Unauthorized or 500 Internal Server Error, despite using the correct API key and headers.

ZIP File Integration: I found a sample ZIP file for the API, which supposedly includes all the necessary files for a working integration. However, after extracting and following the instructions, I encountered various errors such as missing dependencies, incorrect routes, and authentication failures.

Has anyone successfully integrated the Delhivery API? Any guidance on troubleshooting integration or using the ZIP file method would be appreciated. Please share any working examples, best practices, or tips.

Google run altering a request payload in very strange way

I’m experiencing a strange issue where my JSON payload is being distorted when deployed on Google Cloud Run, but the same code works perfectly fine on Heroku and localhost. I’m using Laravel 11 and PHP. Here’s what my payload looks like before and after the distortion:

[
    {
        "id": "15758",
        "product_price": "5"
    }
]

To this

{
    "0": {
        "id": "15758",
        "product_price": "5"
    },
    "q": "/v1/products/variants" // this is strangely added by google, it is the URL of the request endpoint
}

Strangely google run adds a key “q” with the url of the request endpoint.

How can I display client single data and not duplicate them

Please how can I display client single data and not duplicate them. As you can see on the result it duplicate each client twice.

When I run the code this is what I get

enter image description here

This is what I want

enter image description here

This are MySQL tables

First table

enter image description here

Second table

enter image description here

This is my code

<?php
    require_once 'db_connect.php';
    $varCurDate = date("Y-m-d");
    $sqlabs = "SELECT * FROM tbl_absent HAVING (startDate = '$varCurDate' AND endDate > '$varCurDate')";
    $resultabs = mysqli_query($conn, $sqlabs);
    if (mysqli_num_rows($resultabs) > 0) {
        while ($rowabs = mysqli_fetch_assoc($resultabs)) {
            $varSpecialId = $rowabs["specialId"];
            $varUserName = $rowabs["userName"];
            $varStartDate = $rowabs["startDate"];
            $varEndDate = $rowabs["endDate"];


            $sql = "SELECT * FROM tbl_clients WHERE (specialId != '$varSpecialId') GROUP BY specialId";
            $result = mysqli_query($conn, $sql);
            while ($row = mysqli_fetch_assoc($result)) {
                echo "
                    <tr>
                        <td>" . $row["userId"] . "</td>
                        <td>" . $row["userName"] . "</td>
                        <td>" . $row["userEmail"] . "</td>
                        <td>" . $row["userPhone"] . "</td>
                        <td>" . $row["specialId"] . "</td>
                    </tr>
                    ";
            }
        }
    } else {
        echo "0 results";
    }
    mysqli_close($conn);
    ?>

How can I search for data if a template is specified in the database?

Are there templates like
abc????cba
or
??de??df
or any other combination.
But the user will enter the full line, for example, abc1234cba
, and the script needs to output all the lines where this combination exists, taking into account the templates.
Under the symbol ? any letter or number can be implied.

I’m doing it on WP, we’re looking for the ACF field
Have you tried this:


    $vin_regex = str_replace(array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'), '.', $vin_regex);

    
    $meta_query = array(
        array(
            'key' => 'vin',
            'value' => $vin_regex,
            'compare' => 'REGEXP', 
        ),
    );

    $args = array(
        'post_type' => 'product',
        'posts_per_page' => 10,
        'paged' => $paged,
        'meta_query' => $meta_query,
    );

    $query = new WP_Query($args);

It didn’t help

ave you tried this

    $query = "
        SELECT DISTINCT p.ID
        FROM {$wpdb->posts} p
        INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id
        WHERE p.post_type = 'product'
          AND p.post_status = 'publish'
          AND pm.meta_key = 'vin'
          AND pm.meta_value LIKE REPLACE(%s, '?', '_')
        LIMIT 10 OFFSET %d
    ";

    $results = $wpdb->get_col($wpdb->prepare($query, $vin_input, $offset));

It didn’t help

How to make WP customize preview on multiple front page selection?

I have developed a theme with multiple page selection like Homepage1.php, homepage2.php, homepage3.php and more. But I have stuck on WordPress preview as page aren’t change dynamically on preview after selection.

The selection is saved well but doesn’t show up on preview by either refresh or postMessage transports, it only show up after reloaded whole page after being saved, below are codes that I have used for WP customization,

Selection page php fuction

function bansta_home_page() {
    if ( get_theme_mod( 'bansta_front_page') === 'home-default' ) {
        $bansta_home = 'default';
    } elseif ( get_theme_mod( 'bansta_front_page' ) === 'home-grid2') {
        $bansta_home = 'grid_2';
    } elseif ( get_theme_mod( 'bansta_front_page') === 'home-grid3' ) {
        $bansta_home = 'grid_3';
    } elseif ( get_theme_mod( 'bansta_front_page') === 'home-grid4' ) {
        $bansta_home = 'grid_4';
    } else {
        $bansta_home = 'default';
    }
    return $bansta_home;
}


$wp_customize->add_setting( 'bansta_front_page', array(
    'default'           =>  $bansta_defaults[ 'bansta_front_page' ],
    'capability'        =>  'edit_theme_options',
    'type'              =>  'theme_mod',
    'sanitize_callback' =>  'bansta_sanitize_select',
    'transport'         =>  'refresh'
));
$wp_customize->add_control( 'bansta_front_page', array(
    'label'             =>  __( 'Front Layout', 'bansta' ),
    'settings'          =>  'bansta_front_page',
    'section'           =>  'bansta_section_frontpage',
    'type'              =>  'select',
    'choices'           =>  array(
        'home-default'      =>  __( 'Default', 'bansta' ),
        'home-grid2'        =>  __( 'Grid-2', 'bansta' ),
    'home-grid3'        =>  __( 'Grid-3', 'bansta' ),
    'home-grid4'        =>  __( 'Grid-4', 'bansta' )
    )
));

scripts for preview

( function( $ ) {
    wp.customize( 'bansta_front_page', function( newval ) {
        newval.bind( function( to ) {
            $( '.content-wrapper' ).html( to );
        });
    });
}) ( jQuery );

index.php contain these codes for page selection;

$basta_home_layout = get_theme_mod( 'bansta_front_page', '' );
get_template_part( '/libs/front/home-' .$bansta_home );

As you can see I have multiple selection with multiple homepages such as home-defaut.php, home-grid2.php and so on, can someone help me to achieve this issue, what code did I miss????.

Laravel 11 – I want to create dynamic routing for multi level access but without passing the same parameter each time

In laravel 11 i setup my route like this :

      then: function(){
                Route::middleware(['web', 'admin'])->prefix('admin')->name('admin.')->group(base_path('routes/admin.php'));
                Route::middleware(['web', 'user'])->prefix('u/{userid?}')->name('user.')->group(base_path('routes/user.php'));
            },

but there is a problem when i want to each any route of user.php file: i need to add userid parameter each time

can i automate this process so the userid will automatically injected to the route

I don’t want to write this type of syntax each time :

<a href="{{ route("user.comment.create", Auth::id()) }}"></a>

I think laravel have the good approach for this : I want to use that approach !

anyone tell me the right way to do this…

How do i write more elegant code to search for an elements’ property in PHP?

I’m scraping a webpage for some metatags that look like this :

<meta property="og:phone_number" content="01234 567890">

They may or may not exist. I’ve created some code that works, but I don’t think it’s as elegant as it could be:

if ($html->find('meta[itemprop="phone_Number"]')) { $event["phone_number"]=$html->find('meta[property="og:phone_number"]',0)->getAttribute('content'); } 

I’d like to do this without the if, and when the phone_number metatag or the metatag property does not exist, just silently continue.

How to replace hyperlink dynamically using PHP

I want to replace the following hyperlinks dynamically

from

<a href="/xsearch2?q=some search/21">21</a>

to

<a href="/xsearch2?q=some search&page=21">21</a>

how can I do that dynamically

have tried the following

preg_replace('#<a.*?>([^>]*)</a>#i', '<a href="/xsearch2?q='.$key.'&page=$1">$1</a>', $pagination);

but its changing the hyperlinks also, just want to remove the last slash / from hyperlinks and add &page=

How can I integrate stripe with flutter frontend and php backend?

I want to use my own payment form to process payments using flutter frontend and php backend. The form will be created with the following fields: amount, card holder name, card number, expiry date, cvv and a submit button in flutter. I dont want to use stripe’s payment form.

I have created an account with stripe and have the publishable and secret keys. ( test account)

Now when I click the submit button after the form has been filled up I want to create a stripe token (which uses the publishable key) and send the token details to my php backend, which will then process the payment and return / success /error codes. The php backend will use the secret key provided by stripe.

Is it possible to do this. I am do so using javascript and php library from stripe in our web application.

If you could guide me as to how to do this it will be of great help. Is this the right way to use your own payment form for flutter / php

PHP inheritance in constructor

I’m doing tests.
Given this code snippet

<?php

class Point
{
    public $x;
    public $y;

    public function __construct($x, $y) {
        $this->x = $x;
        $this->y = $y;
    }
}

class Point3D extends Point
{
    public $z;

    public function __construct($x, $y, $z) {
        $this->z = $z;
    }
}

$p = new Point3D(1, 2, 3);
echo sprintf('(%d, %d, %d)', $p->x, $p->y, $p->z);

I’m confused because the correct answer seems to be :

(0,0,3)

But $x and $y are not initialized in child class.
__parent() is not called
When I run the code in a sandbox, it does give the expected answer
When I ask ChatGPT about it, he gives the answer I would have given : $x, $y are not initialized before… => fatal error

The question is why both me and ChatGPT are wrong
What’s the principle here ?