Drupal redirects to homepage on batch page.

Created on 20 March 2016, about 8 years ago
Updated 19 September 2023, 9 months ago

I've noticed weird issue which causing the redirect to home page while running batch script (such as indexing the site).

I've tracked the problem to request_path() which returns empty string despite I'm being on /batch?op=start&id=10916 page, as result I'm redirected to the home page which is not expected.

I'm using PHP built-in server which is probably the reason of such problem (ran by: php -S localhost:1234).

In request_path() I've tracked the problem to the following code which "thinks" this is a home page request:

    // If the path equals the script filename, either because 'index.php' was
    // explicitly provided in the URL, or because the server added it to
    // $_SERVER['REQUEST_URI'] even when it wasn't provided in the URL (some
    // versions of Microsoft IIS do this), the front page should be served.
    if ($path == basename($_SERVER['PHP_SELF'])) {
      $path = '';
    }

These are my results of some testing the values by the following line:

    var_dump('PHP_SELF = ' . $_SERVER['PHP_SELF'], 'basename = ' . basename($_SERVER['PHP_SELF']), '$path = ' . $path); exit;

For example:

Page: /batch?op=start&id=10916

string 'PHP_SELF = /index.php/batch' (length=27)
string 'basename = batch' (length=16)
string '$path = batch' (length=13)

Problem: Since PHP_SELF basename equals to batch, Drupal thinks this is the file, therefore removing the correct value of $path

Page: update.php

string 'PHP_SELF = /update.php' (length=22)
string 'basename = update.php' (length=21)
string '$path = update.php' (length=18)

This is correct.

Page: /user

string 'PHP_SELF = /index.php/user' (length=26)
string 'basename = user' (length=15)
string '$path = user' (length=12)

This is not correct and will result in homepage page.

Page: /admin/reports
string 'PHP_SELF = /index.php/admin/reports' (length=35)
string 'basename = reports' (length=18)
string '$path = admin/reports' (length=21)

This won't redirect to homepage.

I think the fix should be similar as proposed in #223496: Use SCRIPT_FILENAME instead of PHP_SELF β†’ 7 years ago, so to use $_SERVER['SCRIPT_FILENAME'] instead.

So basename of SCRIPT_FILENAME will return: index.php, not batch, in case of batch case.

πŸ› Bug report
Status

Postponed: needs info

Version

7.0 ⚰️

Component
BootstrapΒ  β†’

Last updated 9 days ago

No maintainer
Created by

πŸ‡¬πŸ‡§United Kingdom kenorb

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024