Laravel blade strange execution sequence [closed]

I came across a Laravel tutorial. It’s about authentication system and creating login interface.
There is some strange code that I don’t understand.

There is a login form submitting a post request to server to authenticate. Based on input data, it may fail with errors (Like invalid email or …). There is a field under the form to show those errors:

@if ($errors->any())
  <ul>
    @foreach ($errors->all() as $error)
      <li>{{ $error }}</li>
    @endforeach
  </ul>
@endif

PHP directives execute on server side (?), so how it shows errors after submitting the form? Page is already loaded. So how it works?

PHP web scraping – Why would cURL suddenly stop working? [closed]

I’ve been scraping a webpage with cURL for many years using this program, but it suddenly no longer works. Any suggestions on how to continue scaping this page?

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://www.example.com");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);  

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

$data = curl_exec($ch);

curl_close($ch);

How to register a custom REST API endpoint in WordPress?

I’m learning WordPress and want to create a custom REST API endpoint that returns JSON data. I read about the register_rest_route() function but I’m not sure where to put the code or how to test it properly.

Can someone give a basic example of creating a REST route in WordPress with authentication, and how to call it?

Thanks in advance!

I created a plugin and used register_rest_route() inside the init hook, but when I visit the route URL, it shows a 404 error. I’m not sure if I’m using the right hook or path.

I want a basic example to register a REST API route in WordPress that returns JSON like {“status”: “success”} and how to test it in the browser.

How to create an increase system + multiplier where every time you buy a slot, price increases [closed]

I need some help with an increase system where price gets higher the more slots you buy
The slots are basically items in a shop. I have the shop and item system already in the website. But there is no increase system so its a new mechanic.

I’ve pretty much gotten this direction:
a flat multiplier, add a field that’s a purchase multiplier to shop stock, grab a user’s total lifetime purchases and do the math

I couldn’t find any info online about a multiplier
Is there someone that can help and maybe walk me though portions of the multiplier so I could understand it? I never dealt with multipliers before which is why I’m stuck.

I can provide code snippets if needed, as I’m not sure what to provide.
This is coded in php/laravel.

Thank you!

Why isn’t AWS PHP SDK setting Content Disposition for a presigned URL?

I’m having an issue with generating a presigned URL for S3 using AWS SDK for PHP. Here is my request, $s3 is an instance of S3Client:

$request = $s3->createPresignedRequest($s3->getCommand('getObject',array(
            'Bucket' => $myBucket,
            'Key' => $filename,
            'ContentDisposition' => 'inline'
        )),
    '+1 hour');

After looking around on stack overflow, and running through every page of documentation on the SDK I can find, I’ve tried setting ‘ContentDisposition’, ‘ResponseContentDisposition’, ‘response_content_disposition’ and ‘Content-Disposition’ in the headers, to no avail.

No matter what, the content disposition is set as “attachment” and clicking the presigned URL starts a download of the file. I’ve also experimented with the same headers above when I’m sending the object with putObject – still no luck. Any ideas?

Get product id inside of Quote in magneto 2

I want to alter product price in magento 2.4.7 To do it in catalog and single view i have plugin

<type name="MagentoCatalogModelProduct">

inside afterGetPrice. This is wrok for me well.

However after i add product in checkout price alters. So i have another plugin
<type name="MagentoQuoteModelQuote">, and inside
beforeCollectTotals

My problem is that i want to change price based on product id(external logic per product).
I can do

    public function beforeCollectTotals(MagentoQuoteModelQuote $subject)
    {
        /**
         * @var $item Item
         */
        foreach ($subject->getAllItems() as $item) {
            /**
             * @var $product Product
             */
            $product = $item->getProduct();

But now my if product is configurable i have id of parent not a child.
I Found that i can do

            if ($product->getTypeId() === 'configurable') {
                $id = array_first($item->getData()['qty_options'])->getData('product_id');
            } else {
                $id = $product->getId();
            }

To get **child id** But i wonder is there any alternatives here ? To get this working ? 

Windows.open losing session in PHP [closed]

I have a simple chat scenario in my PHP web app. On the other side I have selenium based python script to show automatiom. The purpose is that when someone sends link, the selenium bots clicks on the URL and visits it

The code is that bot logs in using username abc and password abc and a sessiond ID is set in PHP.

When it receives a link it does the windows.open(link) and then returns back to original window

The issue I am facing is that if I send a link against a different domain and that domain posts data to original domain.. the session values are not preserved.. typical csrf scenario.. what I should do in this case

What is the difference between PHP’s mb_strolower() and IntlChar::tolower()?

I have been testing PHP’s mb_strtolower() and IntlChar::tolower() functions. By and large they give the same results, but I notice that they give different results for the Turkish dotted I ‘İ’: mb_strtolower() gives ‘i̇’ whereas IntlChar::tolower() gives ‘i’.

Would you expect them to give the same results? Or is there another method that would give the same result as mb_strtolower()? I’m looking for an alternative to mb_strtolower() when the mbstring extension isn’t available.

Is there any way to have a loading memory cache in PHP?

I want to avoid to use database connection to retrieve very repetitive content of my web app.

I would like to know if exists any way to use a memory cache (memcache?) with time expiration and loading feature.
Just to be clear whan I mean for time expiration and loading feature it is something like Java Guava LoadingCache library. A memory storage that expires after a defined time span and then provide a method to retrieve that content externally.

My goal is to use this cache for x seconds after that the content is refreshed from database.
I know the database has its own cache but for sure it makes more overhead than a memory storage.

repeat select users when login [closed]

I’m use default login program in laravel 12.

It’s work very well before few day ago.

When I try to login my web, it will select user again and again event I delete my update in that day.

I’m listen my query, and log is like this.

[2025-06-06 04:19:23] local.INFO: SQL Query {"sql":"select * from `users` where `id` = ? limit 1","bindings":[1],"time":0.14} 
[2025-06-06 04:19:23] local.INFO: SQL Query {"sql":"select * from `users` where `id` = ? limit 1","bindings":[1],"time":0.15} 
[2025-06-06 04:19:23] local.INFO: SQL Query {"sql":"select * from `users` where `id` = ? limit 1","bindings":[1],"time":0.16} 
[2025-06-06 04:19:23] local.INFO: SQL Query {"sql":"select * from `users` where `id` = ? limit 1","bindings":[1],"time":0.16} 
[2025-06-06 04:19:23] local.INFO: SQL Query {"sql":"select * from `users` where `id` = ? limit 1","bindings":[1],"time":0.16} 
[2025-06-06 04:19:23] local.INFO: SQL Query {"sql":"select * from `users` where `id` = ? limit 1","bindings":[1],"time":0.15} 
[2025-06-06 04:19:23] local.INFO: SQL Query {"sql":"select * from `users` where `id` = ? limit 1","bindings":[1],"time":0.15} 
[2025-06-06 04:19:23] local.INFO: SQL Query {"sql":"select * from `users` where `id` = ? limit 1","bindings":[1],"time":0.14} 
[2025-06-06 04:19:23] local.INFO: SQL Query {"sql":"select * from `users` where `id` = ? limit 1","bindings":[1],"time":0.15} 

The most weird thing is this program is work at another computer.

I found that delete this line in SessionGuard.php will fix the problem, but $request->user() will be null.

protected function updateSession($id)
{
    $this->session->put($this->getName(), $id);  // delete this line

    $this->session->migrate(true);
}

my login function in AuthenticatedSessionController

public function store(Request $request): RedirectResponse
{
    $request->validate([
       'email' => 'required|email',
       'password' => 'required',
    ]);
    $request->authenticateAccount(); // crash function

    $request->user()->createToken('api');
    return redirect('/homeManage');
}

crash function

public function authenticate(): bool
{
    $result = $this->ensureIsNotRateLimited();

    if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) { // crash in this condition process
        RateLimiter::hit($this->throttleKey());

        throw ValidationException::withMessages([
            'email' => __('auth.failed'),
        ]);
    }

    RateLimiter::clear($this->throttleKey());
    return $result;
}

Can someone tell me how to fix it?

Symfony EasyAdmin: How to embed and correctly display YouTube iframe inside a CollectionField?

I’m working on a Symfony project using EasyAdmin. I have a Page entity that contains a collection of Step entities. Each Step has a field called intro where I want to store and display a YouTube iframe embed code.

In my EasyAdmin CRUD controller, I use this configuration:

yield CollectionField::new('steps', 'Steps')
    ->setEntryType(IntroStepType::class)
    ->allowAdd()
    ->allowDelete()
    ->renderExpanded()
    ->addJsFiles(Asset::fromEasyAdminAssetPackage('field-text-editor.js')->onlyOnForms())
    ->addCssFiles(Asset::fromEasyAdminAssetPackage('field-text-editor.css')->onlyOnForms());

And my custom form type for ‘steps’ looks like this:

class IntroStepType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('title', TextType::class, [
                'label' => 'Title',
            ])
            ->add('element', TextType::class, [
                'label' => 'Element',
            ])
            ->add('intro', TextEditorType::class, [
                'label' => 'Instructions',
            ]);
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => Step::class,
        ]);
    }
}

Problem:

I can enter YouTube iframe embed code into the intro field via the text editor in easyadmin, but when viewing the detail page, the iframe is not rendered as HTML. Instead, it shows as plain text.

This is my Stimulus controller where i load the data in:

import { Controller } from '@hotwired/stimulus';
import introJs from 'intro.js';
import '../vendor/intro.js/introjs.css';

export default class extends Controller {
    async connect() {
        this.intro = introJs();

        this.baseOptions = {
            showBullets: false,
            showPrevButton: true,
            nextLabel: 'Next',
            prevLabel: 'Previous',
        };

        this.intro.setOptions(this.baseOptions);

        const params = new URLSearchParams(window.location.search);

        if ('true' === params.get('tutorial')) {
            await this.startTutorial();
        }
    }

    async startTutorial() {
        const path = encodeURIComponent(window.location.pathname);

        try {
            const response = await fetch(`/tutorial?path=${path}`);

            if (!response.ok) {
                console.error('Error loading tutorial data:', response.status, response.statusText);

                return;
            }

            const data = await response.json();
            if (!data.steps?.length) return;

            const steps = data.steps.filter(step => !step.element || document.querySelector(step.element));
            if (steps.length === 0) return;

            const options = {
                ...this.baseOptions,
                steps,
                doneLabel: data.next ? 'Next' : 'Done',
            };

            this.intro.setOptions(options);

            this.intro.oncomplete(() => {
                if (data.next) {
                    const nextUrl = new URL(window.location.origin + data.next);

                    nextUrl.searchParams.set('tutorial', 'true');

                    window.location.href = nextUrl.toString();
                } else {
                    this.removeTutorialQueryParam();
                }
            });

            setTimeout(() => this.intro.start(), 100);
        } catch (error) {
            console.error('Network error:', error);
        }
    }

    removeTutorialQueryParam() {
        const url = new URL(window.location);

        url.searchParams.delete('tutorial');

        window.history.replaceState({}, document.title, url);
    }
}


Any advice or examples are much appreciated.

Extra characters on php soapclient request XML

Yet another problem with PHP soapclient, I hope someone can show me the correct way of doing this:

Here is a portion of the parameter array to keep things simple:

$params = array (
        'communication' =>
        [
            'user-configuration' =>
            [
                'ruleset' =>
                [
                    'rule' => 
                     [
                         '_' => '',
                         'id' => '999',
                         'conditions' =>
                         [
                            'rule1' => 'true',
                         ],
                         'actions' =>
                         [
                            'forward-to' =>
                             [
                                'target' => '123456'
                             ],
                         ],                         
                     ],                     
                ],
            ],
        ],    
); 

I call the soapclient as follows:

   $client = new SoapClient
            ($wsdl, 
            array(
                'location' => "http://$ip:8080/CAI3G1.2/services/CAI3G1.2",
                'uri'      => "http://$ip:8080/CAI3G1.2/services/CAI3G1.2",
                'exceptions' => true,
                'cache_wsdl' => WSDL_CACHE_NONE,   
                'connection_timeout' => 5,
                'trace'    => 1,
                'encoding'=>' UTF-8'
        ));    
    
    $header = new SoapHeader('http://schemas.ericsson.com/cai3g1.2/','SessionId',$sessionID,false);
    $client->__setSoapHeaders($header);      
   try {
      $response = $client->Set($params);
    } catch(Exception $e){
      if ($debug) print_r($e);
      return $e;
    }
return $response;

The XML generated has an extra unwanted part highlighted as follows:

                <ns2:communication>
                    <ns2:user-configuration>
                        <ns2:ruleset>
                            <ns2:rule id="999">
                                <ns2:id>999</ns2:id>
                                <ns2:conditions>
                                    <ns2:rule1>true</ns2:rule1>
                                </ns2:conditions>
                                <ns2:actions>
                                    <ns2:forward-to>
                                        <ns2:target>123456</ns2:target>
                                    </ns2:forward-to>
                                </ns2:actions>
                            </ns2:rule>
                        </ns2:ruleset>
                    </ns2:user-configuration>
                </ns2:communication>

the server doesnt like these extra line added on the request:

<ns2:id>999</ns2:id> 

if I put the same request on soapUI the request does not contain this extra values, it is as follows, which the server accepts:

            <ns2:communication>
                <ns2:user-configuration>
                    <ns2:ruleset>
                        <ns2:rule id="999">
                            <ns2:conditions>
                                <ns2:rule1>true</ns2:rule1>
                            </ns2:conditions>
                            <ns2:actions>
                                <ns2:forward-to>
                                    <ns2:target>123456</ns2:target>
                                </ns2:forward-to>
                            </ns2:actions>
                        </ns2:rule>
                    </ns2:ruleset>
                </ns2:user-configuration>
            </ns2:communication>

nginx configuration with dynamic root for subfolder

I’m trying to write an nginx configuration for a change in our application directory structure. I want to be able to support developers who are running both the old version and the new version for the next few years.

In the new version of the application the only real change is that the web accessible code has been moved to a public directory.

We have a range of PHP files which are accessed directly, and some which are accessed through a router, r.php. We also have some which are accessed via a javascript endpoint which minifies (and caches) but the files are accessed using URLs in the form http://example.com/oldsite/javascript.php/some/js/file.

Each instance of the application is within a directory, for example:

├── oldsite
│   ├── index.php
│   ├── javascript.php
│   ├── mod
│   │   └── book
│   │       └── index.php
│   └── r.php
└── newsite
    └── public
        ├── index.php
        ├── javascript.php
        ├── mod
        │   └── book
        │       └── index.php
        └── r.php

The oldsite is access at http://example.com/oldsite/ and the newsite at http://example.com/newsite/.

I’m trying (and failing) to write an nginx configuration that will automatically handle both the old and new sites correctly.

This is what I have so far:

set $root /srv/sites
index index.php;

set $site "";
if ($uri ~ /(?<site>[^/]+)(?<relpath>/?.*)) {
    set $site $site;
}

set $docroot "$root/$site";
if (-d "/$docroot/public") {
    set $docroot "$root/$site/public";
}

location ~ /(?<site>[^/]+)(?<relpath>/.*.php)(/?|$) {
    root $docroot;
    include /opt/homebrew/etc/nginx/blocks/php.conf;
}

location ~ ^/(?<site>[^/]+)/?$ {
    root $docroot;

    rewrite ^(.*)/?$ $1/index.php last;

    location ~ .php$ {
        include /opt/homebrew/etc/nginx/blocks/php.conf;
    }
}

location ~ ^/(?<site>[^/]+)/?(?<relpath>.*)$ {
    root $docroot;

    location ~ .php$ {
        include /opt/homebrew/etc/nginx/blocks/php.conf;
    }
    try_files /$relpath /$relpath/ /r.php;
}

My php.conf looks like this:

fastcgi_split_path_info ^(.+.php)(/.*)$;

# Save path_info before try_files resets it
set $path_info $fastcgi_path_info;

include fastcgi_params;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $docroot$relpath;
fastcgi_param DOCUMENT_ROOT $docroot;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index index.php;

What is working:

  • http://example.com/oldsite (returns /index.php)
  • http://example.com/oldsite/ (returns /index.php)
  • http://example.com/oldsite/index.php
  • http://example.com/oldsite/javascript.php/some/file
  • http://example.com/oldsite/mod/book/index.php
  • http://example.com/newsite (returns /index.php)
  • http://example.com/newsite/ (returns /index.php)
  • http://example.com/newsite/index.php
  • http://example.com/newsite/mod/book/index.php
  • http://example.com/newsite/javascript.php/some/file

What is not working:

  • http://example.com/oldsite/notfound (returns 404) — should use /r.php
  • http://example.com/oldsite/mod/book (returns 404) — should use /mod/book/index.php
  • http://example.com/oldsite/mod/book/ (returns 404) — should use /mod/book/index.php

Digging into the logs, the final location match is used (correctly) but the try_files directive is not working as I expect.

2025/06/05 09:00:22 [debug] 80884#0: *31 generic phase: 13
2025/06/05 09:00:22 [debug] 80884#0:*31 try files handler
2025/06/05 09:00:22 [debug] 80884#0: *31 http script var: "/srv/sites/newsite/public"
2025/06/05 09:00:22 [debug] 80884#0:*31 http script copy: "/"
2025/06/05 09:00:22 [debug] 80884#0: *31 http script var: "mod/book/"
2025/06/05 09:00:22 [debug] 80884#0:*31 trying to use file: "/mod/book/" "/srv/sites/newsite/public/mod/book/"
2025/06/05 09:00:22 [debug] 80884#0: *31 http script copy: "/"
2025/06/05 09:00:22 [debug] 80884#0:*31 http script var: "mod/book/"
2025/06/05 09:00:22 [debug] 80884#0: *31 trying to use dir: "/mod/book/" "/srv/sites/newsite/public/mod/book/"
2025/06/05 09:00:22 [debug] 80884#0:*31 try file uri: "/mod/book/"
2025/06/05 09:00:22 [debug] 80884#0: *31 generic phase: 14
2025/06/05 09:00:22 [debug] 80884#0:*31 content phase: 15
2025/06/05 09:00:22 [debug] 80884#0: *31 content phase: 16
2025/06/05 09:00:22 [debug] 80884#0:*31 http script var: "/srv/sites/newsite/public"
2025/06/05 09:00:22 [debug] 80884#0: *31 open index "/srv/sites/newsite/public/mod/book/index.php"
2025/06/05 09:00:22 [debug] 80884#0:*31 internal redirect: "/mod/book/index.php?"

I can see that it’s trying to use the directory, which it finds successfully, but then that turns into an internal redirect, which then gets processed from the top and the $site var is turned into mod, which doesn’t then exist.

Likewise with a fallback URL:

2025/06/05 07:00:29 [debug] 80884#0: *11 try files handler
2025/06/05 07:00:29 [debug] 80884#0: *11 http script var: "/srv/sites/newsite/public"
2025/06/05 07:00:29 [debug] 80884#0: *11 http script copy: "/"
2025/06/05 07:00:29 [debug] 80884#0: *11 http script var: "mod/book/notfound"
2025/06/05 07:00:29 [debug] 80884#0: *11 trying to use file: "/mod/book/notfound" "/srv/sites/newsite/public/mod/book/notfound"
2025/06/05 07:00:29 [debug] 80884#0: *11 http script copy: "/"
2025/06/05 07:00:29 [debug] 80884#0: *11 http script var: "mod/book/notfound"
2025/06/05 07:00:29 [debug] 80884#0: *11 trying to use dir: "/mod/book/notfound" "/srv/sites/newsite/public/mod/book/notfound"
2025/06/05 07:00:29 [debug] 80884#0: *11 trying to use file: "/r.php" "/srv/sites/newsite/public/r.php"
2025/06/05 07:00:29 [debug] 80884#0: *11 internal redirect: "/r.php?"

It’s trying and (correctly) failing to find the file, and then it (correctly) falls back to /r.php, which it does find… only to redirect in the same way.

I feel like there’s something really obvious that I’m missing. I have thought about using a series of if tests instead of if tests, but this feels wrong. Another option would be some kind of proxy to an internal server directive I guess?

Thanks