PHP session management broken even though it works in 3 other environments

I have a large PHP app that’s been working for YEARS, it worked in an Apache/cPanel/Mysql hosted local data center, it worked in Docker with the standard docker images, and in a few other places over the years.

Now, it appears that my $_SESSION variables aren’t being preserved between page flips. It’s not me doing it, I’ve thoroughly debugged the code and the $_SESSION variables are definitely not being preserved between page flips.

What is the problem here? Is there something in the php.ini I need to pay attention to? Right now I’m running in the AWS cloud with the standard Bitnami (VMWare) distribution which contains Apache and MySql, so it should be a pretty identical environment to what I was using before. The pages are being served, and PHP appears to be working fine (once I get inside the page it’s all good). However all the $_SESSION variables are getting clobbered between page flips.

Is there another way to determine the current session ID? It looks like “something” is regenerating my session ID with every page flip. If I call session_id() as the very first line of code at the top of the page, I get a 0. Subsequently then, my logic says “gee, I have no session ID, I better go create one”, and then it calls session_start and after that everything is fine, I can get into the page and everything works as it should “while” the page is being displayed.

I was expecting this to behave in exactly the same way as the previous incarnations of the app, but apparently there’s something different somewhere, and I have no idea where to look. Any and all help is greatly appreciated!

How can i format a file size using php?

I have a form where i am uploading a file after successfully file uploaded i want to show a size of each file with KB, MB, GB depends on the file size.

Like this

<div class="d-flex align-items-center gap-3">
  <img src="{{asset('images/icons/file-icon.svg')}}" alt="" style="width: 70px;height: 70px;border-radius: 10px;">
  <div>
    <p class="font-weight-bold m-0 text-primary-dark">{{ $media->name }}</p>
    <p class="m-0 font-weight-bold text-primary-dark">{{ formatFileSize($media->size) }}</p>
  </div>
</div>

I have create a function in which i am sending a size like this in my blade

{{ formatFileSize($media->size) }}

this should give me a proper format with the unit

PHP-FPM (ZTS) service stuck on ‘activating’ but is working, then fails after 20 Minutes

i have quite a weird problem with my php-fpm.service. I use Ubuntu 22.04 and I compiled PHP (ZTS) 7.4.33 and 8.0.26 from source with --with-apxs2=/usr/bin/apxs2, --enable-parallel and other Options successfully. Created the phplib.so and configured everything to work with Apache2. FPM is set to run in Socket-Mode

With 7.4 everything works great. I start the FPM service and Apache is processing PHP-Files.

However with 8.0 i got a weired Problem. When i use systemctl --no-pager start php8.0-zts-fpm.service it shows Starting php8.0-zts-fpm (via systemctl): php8.0-zts-fpm.service and hangs there until timeout.

So i tried systemctl --no-pager --no-block start php8.0-zts-fpm.service and checked Apache and php-info and everything works just like 7.4 (it shows version 8.0). fpm.log shows:

[31-Aug-2023 11:47:07] NOTICE: fpm is running, pid 10674
[31-Aug-2023 11:47:07] NOTICE: ready to handle connections

but when i check the service-status i get:

● php8.0-zts-fpm.service - The PHP 8.0-zts FastCGI Process Manager
 Loaded: loaded (/lib/systemd/system/php8.0-zts-fpm.service; enabled; vendor preset: enabled)
 Active: activating (start) since Thu 2023-08-31 11:47:07 CEST; 6min ago
   Docs: man:php-fpm8.0-zts(8)
Main PID: 10674 (php-fpm)
  Tasks: 3 (limit: 4556)
 Memory: 43.0M
    CPU: 95ms
 CGroup: /system.slice/php8.0-zts-fpm.service
         ├─10674 "php-fpm: master process (/etc/php/8.0-zts/etc/php-fpm.conf)" "" "" "" "" "" ">
         ├─10680 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ">
         └─10681 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ">

Aug 31 11:47:07 wayne-ubuntu-vmware systemd[1]: Starting The PHP 8.0-zts FastCGI Process Manager...

But still, everything works like it should. But after about 20 minutes, it fails:

× php8.0-zts-fpm.service - The PHP 8.0-zts FastCGI Process Manager
 Loaded: loaded (/lib/systemd/system/php8.0-zts-fpm.service; enabled; vendor preset: enabled)
 Active: failed (Result: timeout) since Thu 2023-08-31 11:04:33 CEST; 36min ago
   Docs: man:php-fpm8.0-zts(8)
Process: 8229 ExecStart=/etc/php/8.0-zts/sbin/php-fpm --nodaemonize --fpm-config /etc/php/8.0-z>
Process: 9490 ExecStopPost=/usr/lib/php/php-fpm-socket-helper remove /run/php/php-fpm.sock /etc>
Main PID: 8229 (code=exited, status=0/SUCCESS)
    CPU: 152ms

Aug 31 10:48:13 wayne-ubuntu-vmware systemd[1]: Starting The PHP 8.0-zts FastCGI Process Manager...
Aug 31 11:04:33 wayne-ubuntu-vmware systemd[1]: php8.0-zts-fpm.service: start operation timed out. >

Aug 31 11:04:33 wayne-ubuntu-vmware systemd[1]: php8.0-zts-fpm.service: Failed with result ‘timeout>
Aug 31 11:04:33 wayne-ubuntu-vmware systemd[1]: Failed to start The PHP 8.0-zts FastCGI Process Man>

Configuration is the same for both versions. What did i get wrong? Any help would be apreciated. Thanks in advance!

Allow array of booleanNodes with random keys with Symfony Configurations and default values

I want to achieve the following configuration structure:

app:
    integrations:
        some: true
        random: true
        options: true
        user_can_make_these_up: true

Where I already added some defaults: mykey: true and myotherkey: false

So in this case the compiled configuration should be:

[
    mykey => true,
    myotherkey => false,
    some => true,
    random => true,
    options => true,
    user_can_make_these_up => true,
]

I tried the following:

$rootNode
    ->children()
        ->arrayNode('integrations')
            ->ignoreExtraKeys()
            ->addDefaultsIfNotSet()
            ->children()
                ->booleanNode('mykey')->defaultTrue()->end()
            ->end()
        ->end()
    ->end();

But then I get an error “Unrecognized option “mykey” under “app”. Available option is “integrations”.”

What am I doing wrong?

Stripe Connect – I see private transactions from connected account in my main Stripe account

I have a marketplace website with a Stripe account for processing payments. I have a number of suppliers and I have set them up using Stripe connect. After payment, the appropriate amounts are sent to the suppliers connected stripe accounts and I take a fee, sent to my main Stripe account.

The problem I have is that in my dashboard in Stripe.com when looking at my suppliers connected accounts I can see ALL of their transactions, not just the ones related to sales on my website. If they make a payment or receive money outside of my website I can see that in my Stripe.com dashboard.

The Connection (PHP)

$response = StripeOAuth::token( [
            'grant_type' => 'authorization_code',
            'code'       => $code,
        ] );

We are ready to go live with this site and obviously cant do so with this issue.

I am unable to find the related documentation on the stripe website. Can anyone let me know how to restrict my view to only see transactions from connected accounts that happen on my website?

Why is the email formatted wrong?

In my Laravel 9 system for pistol competition when creating a competition an email is being sent to be able to link to the competition itself.

But the link address is not created the right way.

This is the statement (in notification-html.blade.php):

{{ url($notification->link) }}

and it creates this link:

http://shoot.mywire.org/${http://shoot.mywire.org}/app/competitions/39

which does not work of course. It should look like this:

http://shoot.mywire.org/app/competitions/39

It works fine in earlier system on Laravel 5.3

What’s wrong with the statement?

htaccess with 2 or more parameters don´t want work right

I want to rewrite my URLs on localhost. First parameter “p” is the page. all other parameters “param1” – “paramX” schould work when I need them. With only one parameter “p” it works every fine. But now I want editing a second parameter in the URL and just want to echo it first. This works too. But when I click on my menupoints, that only use parameter “p” as links, it don´t work right. I get no errors, but parameter “p” do not change, as it should, but “param1” changed and my menu doesn´t open any right site any more. I am a beginner in htaccess und hope you can help me. In the following I post some screenshots
htaccess File

Parameter “P” for sites alone works well

Get the second parameter and index.php

Getting and echo the second parameter works too

But clicking on menupoint don´t work any more

Links with a-tag look like Projekt or ACP

As you can see, if I click on acp (link with href = “acp”) it doesn´t changed the first parameter. It changed the second and the link doesn´t work any more.
Could you help me and could you tell me what I am doing wrong in my thaccess file?
Kind regards,

Richard from Germany

I tried to change the URL, but i doesn´t work. And i edited the thaccess file multiple times with try and error the last day and this is the best result I got. And the other possibilities from stayoverflow, who schowed up, doesn´t help me.

How to bind nested data on livewire when using checkbox?

Im try using checkbox in livewire 2.x, its ok when using single property. But its not worked when using nested property.

blade :

@foreach ($questions as $key => $question)
    <div class="card card-primary">
        <div class="card-body">
            <div class="section-title mt-0">{{ $question->description }}</div>
            <div class="form-group">
                @foreach ($question->choices as $choice)
                    <div class="form-check form-check-inline col-12 col-md-5 col-lg-5">
                        <input
                            class="form-check-input"
                            type="checkbox"
                            id="checkbox-choice-{{ $choice->id }}"
                            value="{{ $question->id }}_{{ $choice->id }}"
                            wire:model.defer='answers.{{ $key }}.choices'
                        >
                        <label class="form-check-label" for="checkbox-choice-{{ $choice->id }}">{{ $choice->description }}</label>
                    </div>
                @endforeach
            </div>
        </div>
    </div>
@endforeach

then on component :

public $answers = [];

public $rules = [
    'answers' => 'required|array|min:1',
];

public function submitAnswers()
{
    /** @var array $validData */
    $validData = $this->validate();
    Log::info('' . json_encode($validData));

}

example result :

{"answers":[{"choices":"42_167"}]}

property choices only returns a string result even though it has selected multiple choices, how to make property choices an array?

An uncaught Exception was encountered Type: ArgumentCountError Message: time() expects exactly 0 arguments, 6 given [closed]

An uncaught Exception was encountered Type: ArgumentCountError

Message: time() expects exactly 0 arguments, 6 given

Filename: C:xampphtdocsperpuskitaapplicationviewsglobalhome.php

Line Number: 24

Backtrace:

File: C:xampphtdocsperpuskitaapplicationviewsglobalhome.php
Line: 24 Function: time

File: C:xampphtdocsperpuskitaapplicationcontrollersBuku.php
Line: 15 Function: view

File: C:xampphtdocsperpuskitaindex.php Line: 315 Function:
require_once

Code in line 24

$endDate=date("t",time(0,0,0,$month,$day,$year));

How to upload text with image to Linkedin using PHP?

I try to upload text, image and a link using Linkedins rest API (https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin#create-an-image-share). But I do not succeed. Uploading the post returns an error: ERROR :: /content/article/thumbnail :: Invalid Urn format. Invalid prefix. Urn urn:li:digitalmediaAsset:…

Here is my code. Are there ideas or any hints?

// upload image
$uploadUrl = 'https://api.linkedin.com/rest/assets?action=registerUpload';
$requestData = [
    'registerUploadRequest' => [
        'recipes' => ['urn:li:digitalmediaRecipe:feedshare-image'],
        'owner' => 'urn:li:person:'. $this->provider->linkedin_id,
    ],
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uploadUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestData));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $this->provider->social_access_token,
    'Linkedin-Version: '. $this->linkedin_version,
    'Content-Type: application/json',
]);
$response = curl_exec($ch);

// get asset id
$responseArray = json_decode($response, true);
$assetId = $responseArray['value']['asset'];

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($httpCode == 200) {
    // upload picture to url received in response
    $imagePath = rex_path::media($used_machine->pics[0]);

    $uploadUrl = $responseArray['value']['uploadMechanism']['com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest']['uploadUrl'];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $uploadUrl);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($imagePath));
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Authorization: Bearer ' . $this->provider->social_access_token,
        'Content-Type: '. mime_content_type($imagePath),
    ]);
    $response = curl_exec($ch);

    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    curl_close($ch);
    
    if ($httpCode == 201) {
        $this->log('Image "'. $used_machine->pics[0].'" for used machine "'. trim($used_machine->manufacturer .' '. $used_machine->name) .'" uploded. Asset ID: '. $assetId);
    } else {
        // failure uploading image
        $this->log('Failure uploading image "'. $used_machine->pics[0].'" for used machine "'. trim($used_machine->manufacturer .' '. $used_machine->name) .'". API answer: '. $response);
        $return = false;
    }
}

// upload post
if($assetId !== '') {
    $postUrl = 'https://api.linkedin.com/rest/posts';
    $postData = [
        'author' => 'urn:li:person:'. $this->provider->linkedin_id,
        'commentary' => $used_machine->manufacturer .' '. $used_machine->name .': '. SprogWildcard::get('d2u_machinery_export_linkedin_details', $this->provider->clang_id),
        'contentLandingPage' => $used_machine->getUrl(true),
        'visibility' => 'PUBLIC',
        'distribution' => [
            'feedDistribution' => 'MAIN_FEED',
            'targetEntities' => [],
            'thirdPartyDistributionChannels' => []
        ],
        'content' => [
            'article' => [
                'source' => $used_machine->getUrl(true),
                'thumbnail' => $assetId,
                'title' => $used_machine->manufacturer .' '. $used_machine->name,
                'description' => $used_machine->teaser
            ]
        ],
        'lifecycleState' => 'PUBLISHED',
        'isReshareDisabledByAuthor' => false
    ];

    $headers = [
        'Authorization: Bearer '. $this->provider->social_access_token,
        'X-Restli-Protocol-Version: 2.0.0',
        'Linkedin-Version: '. $this->linkedin_version,
        'Content-Type: application/json',
    ];

    $ch = curl_init($postUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $responseHeaders = substr($response, 0, $headerSize);

    curl_close($ch);

    if ($httpCode === 201) {
        // Published successfully
        $exported_used_machine->export_action = '';
        $exported_used_machine->export_timestamp = date('Y-m-d H:i:s');

        // Get post id
        $headerLines = explode("rn", $responseHeaders);
        $xRestliId = null;
        foreach ($headerLines as $headerLine) {
            if (strpos($headerLine, 'x-restli-id:') === 0) {
                $xRestliId = trim(substr($headerLine, 12));
                break;
            }
        }

        if ($xRestliId !== null) {
            $exported_used_machine->provider_import_id = $response['id'];
            $exported_used_machine->save();
        } else {
            echo "x-restli-id nicht im Header gefunden";
        }

        $this->log('Post for used machine "'. trim($used_machine->manufacturer .' '. $used_machine->name) .'" on stream of '. $this->provider->linkedin_id .' published (post id: '. $xRestliId .')');
    } else {
        // Failure publishing post
        $this->log('Failure posting used machine "'. trim($used_machine->manufacturer .' '. $used_machine->name) .'" on stream of '. $this->provider->linkedin_id .': '. $response);
        $return = false;
    }
}

simpleSAMLphp Exception: No module named ‘ldap’ has been installed

Really struggling to find a solution for this problem. I am trying to configure my simpleSAMLphp server to use LDAP for authentication, but am getting exceptions originating from the ‘ldap’ module.

My definition of the LDAP authentication source in the authsources.php, looks like the following:

'ldapauth' => [
        'ldap:LDAP',
        'hostname' => 'ldap.saml.com',
        'port' => 389,

        ...
],

Apparently, 'ldap:LDAP' triggers the exception to occur, the module can not be found. PHP shows the module as enabled.

SimpleSAMLErrorError: UNHANDLEDEXCEPTION
Backtrace:
2 public/_include.php:28 (SimpleSAML_exception_handler)
1 vendor/symfony/error-handler/ErrorHandler.php:607 (SymfonyComponentErrorHandlerErrorHandler::handleException)
0 [builtin] (N/A)
Caused by: Exception: No module named 'ldap' has been installed.
Backtrace:
8 src/SimpleSAML/Module.php:446 (SimpleSAMLModule::resolveClass)
7 src/SimpleSAML/Auth/Source.php:315 (SimpleSAMLAuthSource::parseAuthSource)
6 src/SimpleSAML/Auth/Source.php:358 (SimpleSAMLAuthSource::getById)
5 src/SimpleSAML/Auth/Simple.php:67 (SimpleSAMLAuthSimple::getAuthSource)
4 src/SimpleSAML/Auth/Simple.php:156 (SimpleSAMLAuthSimple::login)
3 [builtin] (call_user_func_array)
2 src/SimpleSAML/HTTP/RunnableResponse.php:72 (SimpleSAMLHTTPRunnableResponse::sendContent)
1 vendor/symfony/http-foundation/Response.php:394 (SymfonyComponentHttpFoundationResponse::send)
0 public/module.php:14 (N/A)

Apple Wallet Pass AutoUpdate – without app

I have successfully created an Apple pass using PHP.
The pass is added to the Apple wallet successfully.

Now, I have to update the pass with a new value for one of the parameters in the pass. How do we update the value? Please refer to a sample PHP script for the same.

I have checked the below sites, Here, they Mentioned only the input and output, as per the document I received the push token,
What should I do after getting the push token?

https://developer.apple.com/library/archive/documentation/PassKit/Reference/PassKit_WebService/WebService.html

Also how to update Google Pay Wallet?

No columns were bound prior to calling SQLFetch

I am currently working on a project with the following techstack:

  • Database: Intersystems IRIS
  • Controller: PHP/PDO with IdiORM

The problem is that the IDs are not in a common format. For example: “ABX||242149||1||0||D” – So there are different keys seperated with “||” as delimiter. As long as the ID’s are like “232||ABH” the request with IdiORM is working but an ID like the first example gives the error message: “No columns were bound prior to calling SQLFetch”.

PHP code:

    class TestController
    {
       public function test()
       {
          $out=IRIS::for_table('')->raw_query("select id from Bestand where artikelnr='430030'")->find_array();
          echo json_encode($out);
       }
    }

Are there any restrictions for IdiORM due to the ID format? It seems like the ORM cant map the given ID to the ID column?

How to check vice-versa combinations in PHP using CSV?

I have a input in CSV as below

  1. if product A has product B and product B has product A this input has to fail.Here, error has to throw for two rows for same category.
  2. if product A has product B and productB has empty and no reverse combination available this input should pass for same category.

scenario1: This has to fail both rows

productInit category productLast
productA     cat1     productB
productB     cat2     productA

scenario2: this has import successfully

productInit category productLast
productA     cat1     productB
productB     cat2    
public function productExists($productInit,$productLast,$data,$category){
 foreach ($data as $item) {
            if ($item['productInit'] === $productLast && $item['category'] === $category && $item['productLast'] === $productInit){
                return true;
    }
}

but it is throwing only for the reverse product not for both rows and scenario 2 is failing.

Herodoc <<<EOD issue

enter image description here

I have a problem where the code stops operating at line 269 and causes an error at line 303. With PHP 8.2.4 running on my localhost, the exact code is functional. Utilizing PHP 7.4, the image above. Will there be any conflicts between 7.4 and 8.2.4?