When is index.php executed in wordpress?

I have this code in the root wordpress installation index.php

define('WP_USE_THEMES', true); file_put_contents("/tmp/test.php", print_r($_SERVER, true)); /** Loads the WordPress Environment and Template */ require( dirname( __FILE__ ) . '/wp-blog-header.php' ); 

I notice that if I comment on the last line so that it only becomes

 define('WP_USE_THEMES', true); file_put_contents("/tmp/test.php", print_r($_SERVER, true)); 

an array printed in /tmp/test.php is deferential !. An array has values ​​such as

 [HTTP_COOKIE] => pll_language=en [REQUEST_URI] => /site_front_page/ 

Why? and yet the code that the /tmp/test.php file should write is placed before the code

 require( dirname( __FILE__ ) . '/wp-blog-header.php' ); 

in both cases?

EDIT: 1 For example, REQUEST_URI should just be

 [REQUEST_URI] => / 
+5
source share
1 answer

There seem to be some requests for index.php. The first time a request is made to the root of the site (before any redirection is performed),

  [REQUEST_URI] => / 

The array is written to the file only OK. However, after wordpress redirects to the following code snippet:

 /** Loads the WordPress Environment and Template */ require( dirname( __FILE__ ) . '/wp-blog-header.php' ); 

and decides what the actual home URL is, then a second request is made to the site, but now to the URL:

 [REQUEST_URI] => /site_front_page/ 

At this point, we are overwriting the very first array that was written to /tmp/test.php.

That's why.

0
source

Source: https://habr.com/ru/post/1260433/


All Articles