Update z/OS Password Using PHP cURL Module

I’m trying to change a password on a z/OS mainframe that I make an FTPS connection to. Working with a legacy codebase and I’m trying to get rid of the exec calls to cURL. You’ll notice all the certificate skipping in the old call…

$exec_string = "CURL -q -v -k -S --ftp-ssl-reqd "ftp://" . $hold_user['dm_ftphost'] . "/" --user " . $hold_user['dm_ftpuser'] . ":" . $hold_user['dm_ftppass'] . "/" . $new_pass . "/" . $new_pass . " -Q "cdup"";

I have been unable to translate this to the cURL PHP module. I’ve tried different combinations of CURLOPT_USER, CURLOPT_PASS, and CURLOPT_USERPWD.

As an example of what I’ve tried…

public function updatePassword($newPass) {
        $options = [
            CURLOPT_URL   => "ftp://" . $this->credentials->getField(Ftp_Credentials::HOST),
            CURLOPT_USERPWD =>  $this->credentials->getField(Ftp_Credentials::USER, ret_aes_pass()) . ":" . $this->credentials->getField(Ftp_Credentials::PASS, ret_aes_pass())
                . "/{$newPass}/{$newPass}"
        ];
        return $this->returnSetResult($this->curl($options));
    }

I know I have to update my password at login so there are few options I can use.

Below are my options for every cURL connection I make in case one of these is keeping me from setting my new password.
(I did comment out CURLOPT_USERNAME and CURLOPT_PASSWORD when I tested the above function)

        $options += [
            CURLOPT_FORBID_REUSE     => true,
            CURLOPT_FTP_USE_EPSV     => false,
            CURLOPT_FTP_SKIP_PASV_IP => true,
            CURLOPT_USERNAME         => $this->credentials->getField(Ftp_Credentials::USER, KDRS_AES_KEY),
            CURLOPT_PASSWORD         => $this->credentials->getField(Ftp_Credentials::PASS, KDRS_AES_KEY),
            CURLOPT_PORT             => $this->credentials->getField(Ftp_Credentials::PORT),
            CURLOPT_VERBOSE          => true,
            CURLOPT_FAILONERROR      => true,
            //CURLOPT_FOLLOWLOCATION   => true,
            CURLOPT_TIMEOUT          => 15,
            // SSL options for secure connection
            CURLOPT_FTP_SSL          => CURLFTPSSL_ALL,              // Use SSL/TLS for FTP
            CURLOPT_FTPSSLAUTH       => CURLFTPAUTH_TLS,             // Authenticate using TLS
            CURLOPT_SSLVERSION       => CURL_SSLVERSION_TLSv1_2,     // Use TLS 1.2 explicitly
            CURLOPT_SSL_VERIFYPEER   => true,                        // Verify the peer's SSL certificate
            CURLOPT_SSL_VERIFYHOST   => self::SSL_VERIFY_HOST_ENABLED,                           // Verify the host's name matches the SSL certificate
            CURLOPT_CAINFO           => PATH_CA_BUNDLE               // Path to your CA certificate bundle
        ];

Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port)

I’m using Xdebug v3.4.0 (with PHP 8.3.9).

I get this error for every request.

I tried other Xdebug versions but still got the issue.

Here my php.ini :

[XDebug]
zend_extension = xdebug
xdebug.mode=debug
xdebug.start_with_request=trigger 

My PhpStorm settings :

Phpstorm settings

Phpstorm settings 2

Don’t hesitate if you need more info.

Thanks

PHP/SQL (MariaDB) – Transaction with self instanciation

I have a method that kill a character and if this character is married to another character, it also kill them.

public function kill(string $reason): void
{
    $this->update(array(
        'character_status'        => "Dead",
        'character_death_reason'  => $reason
    ));

    // To ensure it doesn't make an infinite loop.
    if($this->isMarried() && $reason != "wedding") {
        $husband = $this->getHusband();
        $husband->kill('wedding');
    }
}

This method is called on a code, 300 lines after the transaction started, but can be resumed precisely like that :

// For context, every Character() belong to a City(), and I'm doing a transaction per City.
$city->beginTransaction();

[...]

foreach($characterAlive as $character) {
    $character->kill('because_i_want_to');
}

[...]

$city->commitTransaction();

It does work for every character alive. But if a character have a husband, the transaction goes on a “locked table” issue:

ERROR: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction.

All my concerned tables are in InnoDB storage config and I’m using a Singleton. As I’m acting on different rows (character_id being my PRIMARY KEY A_I), I don’t understand why it does work on the foreach, but not if a Character class instantiates another Character class.

I need this dependence as there is more than 30 ways to reach the kill method.

No, you cannot directly run a PHP script on an Amazon S3 bucket? is that true [closed]

Want to create a simple form that stores information in to a csv file, could it be done using a S3 bucket or does it need proper compute like EC2 or Lambda?

AWS Lambda (serverless approach) – Great for lightweight processing. You can trigger a Lambda function when the form is submitted, process the data, and save the CSV file to S3.

EC2 Instance (traditional approach) – If you need more control over the environment and a persistent application, an EC2 instance can run a web app that handles form submissions and writes CSV files to S3.

AWS API Gateway + Lambda – A more serverless approach where the form submits data via an API, the API Gateway triggers a Lambda function, and the function processes the data into a CSV and saves it in S3.

WordPress Plugins update generates a critical error and I can’t access wp-admin since

I’ve been working on this project for a couple of days, I’m completely new to WordPress and this is a legacy project.

After stating this, I’m completely lock-out from wp-admin. I’ve been handling this project from https://mywebsite.com/wp-admin/, I was about to finish it and then I updated the plugins (silly me), specifically the WooComerce one and since then I can’t regain access to https://mywebsite.com/wp-admin/. I got a 307 error in the process

I’ve scout the internet for answers so I will make a list of what I’ve already try

  1. Change the name of the plugins folder at public_html/wp-content/plugins to public_html/wp-content/plugins.hold to make my plugins inactive and regain access

  2. Change the name of the plugins folder at public_html/wp-content/languages/plugins to public_html/wp-content/languages/plugins-_- to be certain about inner calls to the plugins

  3. Change the row [option_id:35 , option_name:active_plugins] from the wp_options table setting [option_value:a:0:{}] straight from the DB with phpMyAdmin, so it can’t pick the plugins neither from the plugin folder nor the DB

  4. Rename the files with ** .htaccess** string from public_html/ to resolve the 307 error

  5. Change
    define( 'WP_CACHE', true );
    to
    define( 'WP_CACHE', false );
    at public_html/wp-config.php

  6. Change
    define( 'WP_DEBUG', false );
    to
    define( 'WP_DEBUG', true );
    at public_html/wp-config.php

  7. Uncomment the lines

      define('WP_DEBUG_LOG', true);
      define('WP_PROXY_HOST', '192.168.14.1'); 
      define('WP_PROXY_PORT', 3128);

at public_html/wp-config.php

  1. rename the traveler folder at public_html/wp-content/themes/ to traveler.nani to avoid using it as a theme if this was the one producing the error

  2. Change
    define('WP_USE_THEMES', true);
    to
    define('WP_USE_THEMES', false);
    at public_html/index.php

As you can see I’ve tried a couple of things but nothing seems to work, here it’s the screenshot of the problem itself (In Spanish because the webpage it’s on Spanish)

https://mywebsite/wp-admin/

On this message says I should have received an email with instructions to fix the bug. I’ve not received anything. Anyone have encounter the same problem or knows how to fix this situation?

`strip_tags` not working with pretty simple string in PHP

I have a long HTML code that contains <script>, <style>, <div>… tags and strip_tags usually works fine. But with the string below, it’s buggy:

$string = '

    <div>BEGINNING</div>

    <script>
    for (let i=0;i<resultado4448.length;i++) {

    }
    </script>

    <div>END</div>

';

echo strip_tags($string);

The code above outputs:

BEGINNING


for (let i=0;i

Which is incorrect, because the END div was not displayed. I think strip_tags got confused with <resultado4448 believing it is a tag and since it didnt find the closing one, it kept searching till the end of the string.

So, if strip_tags is not reliable for this case, is there any other native function or thing that I can do? I dont want to parse the entire document just to get the tags stripped, I have to parse millions of HTML strings each day and strip_tags is being very good and has a good performance, but if I had to parse all HTML codes, it would take forever.

Why does PHP not find ini files even though it scanned the directory they’re in?

I’m trying to run composer install but it’s not finding my extensions. It suggests I run php --ini as a debug step, and it reports “(none)” additional .ini files parsed:

  - Running `php --ini`

      Loaded Configuration File:         /my_dir/etc/php/php.ini
      Scan for additional .ini files in: /my_dir/etc/php/conf.d

      Additional .ini files parsed:      (none)

But when you look at that directory there are clearly additional .ini files in there:

  - Running `ls -1 /my_dir/etc/php/conf.d`

      000-my.ini
      010-ext-zend_opcache.ini
      100-ext-gmp.ini
      110-ext-imap.ini
      120-ext-intl.ini
      130-ext-ldap.ini
      140-ext-raphf.ini
      150-ext-pq.ini
      160-ext-redis.ini
      170-ext-sqlite3.ini

Any ideas why PHP isn’t finding the .ini files in the directory it claims it’s looking in? What other debugging information could I provide?

Debugging output

The files exist and is loadable:

  - Running `php -c /my_dir/etc/php/conf.d/000-my.ini --ini`

      Loaded Configuration File:         /my_dir/etc/php/conf.d/000-my.ini
      Scan for additional .ini files in: /my_dir/etc/php/conf.d

      Additional .ini files parsed:      (none)

But another file gave me an error as it couldn’t load the so. I think that’s the problem:

Warning: Failed loading Zend extension 'opcache.so' 
(tried: /does/not/exist/php/lib/php/extensions/no-debug-non-zts-20230831/opcache.so 
(/does/not/exist/php/lib/php/extensions/no-debug-non-zts-20230831/opcache.so: 
cannot open shared object file: 
No such file or directory), /does/not/exist/php/lib/php/extensions/no-debug-non-zts-20230831/opcache.so.so 
(/does/not/exist/php/lib/php/extensions/no-debug-non-zts-20230831/opcache.so.so: 
cannot open shared object file: 
No such file or directory)) in Unknown on line 0

Thanks Alex Howansky. Please upvote the comment that suggested this debug method.

PHP lib google/apps-chat upload document failed with Service Account permission error

        ...
        // Create a client.
        $chatServiceClient = new ChatServiceClient([
                'credentials' => "$keyPath/songanhbot-sa-02.json",
            ]
        );

        // Prepare the request message.
        $request = (new CreateMessageRequest())
            ->setParent($space)
            ->setMessage((new Message())->setText($messageText));

        // Call the API and handle any network failures.
        try {
            $chatServiceClient->createMessage($request);

            $request = (new UploadAttachmentRequest())
                ->setParent($space)
                ->setFilename($filePath);

            try {
                $response = $chatServiceClient->uploadAttachment($request);
            } catch (ApiException $ex) {
                printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
            }
        } catch (ApiException $ex) {
            printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
        }

I have coded this to send message and upload attachment to a Space within a Workspace.

The code can send the message successfully but failed for uploading the attachment, here is the error print from the code:

Call failed with message: {
    "message": "This method doesn't support service account authentication. Authenticate with a user account.",
    "code": 7,
    "status": "PERMISSION_DENIED",
    "details": [
        {
            "@type": "type.googleapis.com/google.rpc.Help",
            "links": [
                {
                    "description": "See article Authenticate as a user.",
                    "url": "https://developers.google.com/chat/api/guides/auth/users"
                }
            ]
        }
    ]
}

The json key file is for a service account which has already been added to Domain wide delegation via Workspace Admin(Api Controls).

The scopes enables:

I use PHP yii2 framework version: 2.0.51 and google/apps-chat version: 0.10

Please help!

When using wordpress ACF, how can we programatically add new options to a choice field?

I’m importing some data, and generating posts with ACF information, which works well for text fields, and choice fields where the option already exists – but I’d like to add new options to choice fields as required.

I’d hope this is something easy to do, but starting to suspect it’s either difficult, or I’m barking up the wrong tree.

To put it another way, when looking at a choice field in the admin panel, we can type in a list of choices – I want to be able to add a choice to this list programatically

Enter each choice on a new line. For more control, you may specify
both a value and label like this: red : Red

Choices

[Input text box here]

Enter each choice on a new line. For more control, you may specify
both a value and label like this: red : Red

Symfony deserialize ManyToMany relation into existing objects

I have been trying to deserialize a JSON object with Doctrine ManyToMany relation.

The Categories are always new instances instead of existing objects. My hope is that someone here can show me how to recursively find the objects and replace them with existing objects (and merge the changes if needed ).

I want to use Symfony components and not a 3rd party library.

{
    id: 12,
    name: "360 Wallmount",
    categories: [
        {id: 15},
        {id: 12}
    ]
}

When deserialize the JSON above with Symfony deserializer

$entity = $this->serializerManager->deserialize($product, $request->getContent());

It does not replace the product categories with existing doctrine objects

Here is the Deserialize function

public function deserialize($entity, mixed $data, $groups = null)
{
    $context = [
        AbstractObjectNormalizer::DEEP_OBJECT_TO_POPULATE => true,
        AbstractNormalizer::OBJECT_TO_POPULATE => $entity,
        AbstractNormalizer::GROUPS => $groups
    ];

    return $this->serializer->deserialize($data, $entity::class, 'json', $context);
}

How to stop redirecting users to wp-comments-post.php when receiving an error and display a popup instead

I have a website that allows comments on posts and reviews on woocommerce products.
However, the comment form, if not filled out correctly will automatically redirect users to /wp-comments-post.php to display the error. See image for error.

I want to display any errors like this in a simple popup alert box rather than users seeing WordPress error pages. What is the best way to implement this?

enter image description here

How to upload multi-files in GPT APIs and make a conversation?

I have a web app built with Laravel that connects to the GPT APIs to let users chat with GPT. Now, I want to add a feature where users can upload up to 5 files and have a conversation based on those files. I read the GPT documentation, and while it explains how to upload files, it doesn’t clearly explain how to use those files in a conversation. When I upload a file, I get a file ID in response, but I’m not sure how to use that ID in the chat.

Efficiently Reusing an ORM Model’s Output Structure for Data from a Different Query (PHP ActiveRecord Example)

I’m working with a PHP framework that uses an ActiveRecord ORM (like Yii Framework or similar). I have a scenario where I need to query data from one or more tables (TableA, TableB) and present this data in an API response or view. However, the ideal structure for this output aligns with the field definitions of a specific model (CombinedModel), which isn’t directly mapped to the tables I’m querying.

The CombinedModel has a defined fields() method that specifies how its attributes should be structured for output (e.g., for API serialization). I want to leverage this existing structure without manually reshaping the data after fetching it with a different query.

What is an efficient and idiomatic way within an ActiveRecord ORM to execute a query that joins TableA and TableB, and then have the results formatted according to the fields() definition of CombinedModel?

I use a subquery in the from() clause. PHP:

$subQuery = TableA::find()
    ->select([
        'a_id' => 'table_a.id',
        'b_info' => 'table_b.info',
        // ... more required fields
    ])
    ->joinWith(['tableB'], true, 'INNER JOIN');

$query = CombinedModel::find()
    ->from(['combined_data' => $subQuery])
    ->joinWith(['tableA' => function ($q) {
        $q->on(['tableA.id' => 'combined_data.a_id']);
    }], true, 'INNER JOIN');

When I fetch results using $query->all() or with a DataProvider I hope the output will be structured according to CombinedModel’s fields().

This seems to work for fetching the data.

What are any potential drawbacks or alternative patterns I should consider within an ActiveRecord ORM to reuse a model’s output structure for data fetched through a different query?

Is this subquery approach generally considered good practice for this scenario?

What are more suitable ORM features or patterns?

What are performance implications?

I need a way to dynamically edit the class of a div on one page from a script on another page [closed]

I have an ‘Availability Form’ on my site which allows users to select a date/time they desire to schedule an appointment.

I want to differentiate which dates/times are available (or not) within the Availability form, by using either of two separate CSS ‘class’ variables… ‘available’ or ‘unavailable’.

I’d like to be able to dynamically manage the Availability Form on the ‘Visitor’s Page’ using a mirrored structure on a ‘Manager’s Page’, by toggling the CSS class of a particular selection in the form between ‘avaiable’ or ‘unavailable’and saving the changes.

I am thinking a possible way to achieve this may be an ‘onclick’ javascript function?

But honestly, I am a bit out of my depth on this particular type of coding.
Any advice or help would be greatly appreciated.

I have included a simplified structure below (without any script).

CSS:

.pageContainer {

width: 100%;
max-width: 280px;
margin: auto;
align-items: center;

}

.dayContainer {

float: left;
padding: 10px;
width: 120px;
text-align: center;
margin-bottom: 40px;

}

h1 {

font-family: arial;
text-align: center;

}

.dayHeader {

color: #ffffff;
font-family: arial;
font-weight: bold;
cursor: pointer;
height: 40px; 
line-height: 40px;
background-color: black;    

}

.available {

width: 100%;
color: #ffffff;
font-family: arial;
cursor: pointer;
height: 40px; 
line-height: 40px;
background-color: green;

}

.available:hover {font-weight: bold;}

.unavailable  {

width: 100%;
color: #333333;
font-family: arial;
cursor: pointer;
height: 40px;
line-height: 40px;
background-color: grey;   

} 

.unavailable:hover {font-weight: bold;}

.buttonWrapper {

width:100%;
text-align: center;  

}

VISITOR’S PAGE (Availability Form):

<div class="pageContainer">

<h1>Visitor's Page</h1>

<form action="" method="post" name="availabilityForm">

<div class="dayContainer">
<div class="dayHeader">MONDAY</div>
<button id="VR1-C1" class="available">1:00 PM</button>
<button id="VR2-C1" class="unavailable">2:00 PM</button>
<button id="VR3-C1" class="available">3:00 PM</button>
</div>

<div class="dayContainer">
<div class="dayHeader">TUESDAY</div>
<button id="VR1-C2" class="unavailable">1:00 PM</button>
<button id="VR2-C2" class="available">2:00 PM</button>
<button id="VR3-C2" class="available">3:00 PM</button>
</div>

</form>

</div>

MANAGER’S PAGE

<div class="pageContainer">    

<h1>Manager's Page</h1>

<div class="dayContainer">
<div class="dayHeader">MONDAY</div>
<div id="MR1-C1" class="available" onclick="updateClass">1:00 PM</div>
<div id="MR2-C1" class="unavailable" onclick="updateClass">2:00 PM</div>
<div id="MR3-C1" class="available" onclick="updateClass">3:00 PM</div>
</div>


<div class="dayContainer">
<div class="dayHeader">TUESDAY</div>
<div id="MR1-C2" class="unavailable" onclick="updateClass">1:00 PM</div>
<div id="MR2-C2" class="available" onclick="updateClass">2:00 PM</div>
<div id="MR3-C2" class="available" onclick="updateClass">3:00 PM</div>
</div>

<br><br>

<div class="buttonWrapper"><button>Save Changes</button></div>

</div>