• Resolved petjig

    (@petjig)


    Before upgrading to php 8.1, I had a working clean, separate php page with only php-code on my wordpress site.
    Like this:
    mydomainname/public_html/wp-content/showlist/showlist.php

    The code will no longer accept root paths like: PLUGIN-NAME_ROOT_PATH
    This code will not work either: $rootPath = dirname(__FILE__)
    The page execution stops, codes after this will not show.
    As an example:

    <?php
    require_once( CBXPHPSPREADSHEET_ROOT_PATH . 'lib/vendor/autoload.php' );
    echo "Hello!";
    ?>

    This will NOT load the autoload part and the text Hello! will NOT show when executing.

    I also use Get methods on this particulary showlist.php page, that won’t work either.
    like:
    …. wp-content/showlist/showlist.php?Form=Portrait
    and code is:
    $get_code=$_GET['Form'] ?? '';

    If I put the require_once code on functions.php it will work.

    Anyone have a good answer to this strange problem?

    • This topic was modified 3 years, 6 months ago by petjig.
    • This topic was modified 3 years, 6 months ago by petjig.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator threadi

    (@threadi)

    Check the error log of your hosting. There you should be able to identify the cause of the error.

    My guess is: CBXPHPSPREADSHEET_ROOT_PATH does not exist as a constant. This will throw an error.

    Thread Starter petjig

    (@petjig)

    Thank you for the answer!

    The error log of my hosting only show errors on “wordpress” pages, not on separate php pages (even if they are inside wp-content structure, uploaded with FTP). I don’t know why the hosting is not logging those. The hosting don’t have a cpanel, they have their own (bad) solution on site management.

    The constant CBXPHPSPREADSHEET_ROOT_PATH exist, it’s part of a plugin. As I mentioned, it works in functions.php but not on separate php pages.

    I managed to get it working by creating a template page on wordpress admin panel, but I still wonder why separate php page is only working with simple php codes like echo functions but NOT with file structure functions now… not even dirname(__FILE__) or other standard file structure functions are working, instead they breaks the execution, when it worked without a problem before I upgraded to php 8.1.

    Moderator threadi

    (@threadi)

    In the separate PHP file this constant does NOT exist. You call “showlist.php” directly. Without any wordpress environment. Thus, the file here can not know what this is a constant. It does not matter that this is in any file in parallel or in a subdirectory. You can simply test this by debugging. Write directly after <?php in one line

    var_dump(CBXPHPSPREADSHEET_ROOT_PATH);exit;

    and then call the file. You will probably see NULL as output.

    • This reply was modified 3 years, 6 months ago by threadi.
    • This reply was modified 3 years, 6 months ago by threadi.
    Thread Starter petjig

    (@petjig)

    Ah, of course. I understand that now when you mention it.
    But how strange, that this worked before.

    Do you know if there is a way of integrate my separate php page so it “belongs” to wordpress environment? Some kind of header code on that page or like that?
    I have the working “template page” but that is not really the way I want it, it feels like a provisional solution.

    Again, thank you for the answers!

    Moderator threadi

    (@threadi)

    Include wp-load.php in your file. E.g. via:

    require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');

    You should adapt the path to your system if necessary.

    Thread Starter petjig

    (@petjig)

    WOW! Thanks, threadi!

    Simple as that!

    I wish I knew this before ripping my hair out. I’ve googled hours after hours without finding such easy solution!

    Again, thanks!

    Moderator threadi

    (@threadi)

    Glad if I could help. You are welcome to set the topic to solved.

    Thread Starter petjig

    (@petjig)

    SOLVED! πŸ™‚

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Separate php page not working with php 8.1’ is closed to new replies.