PHP pass variable to include

前端 未结 13 2870
你的背包
你的背包 2020-11-27 17:19

I\'m trying to pass a variable into an include file. My host changed PHP version and now whatever solution I try doesn\'t work.

I think I\'ve tried every op

13条回答
  •  半阙折子戏
    2020-11-27 17:49

    I've run into this issue where I had a file that sets variables based on the GET parameters. And that file could not updated because it worked correctly on another part of a large content management system. Yet I wanted to run that code via an include file without the parameters actually being in the URL string. The simple solution is you can set the GET variables in first file as you would any other variable.

    Instead of:

    include "myfile.php?var=apple";
    

    It would be:

    $_GET['var'] = 'apple';
    include "myfile.php";
    

提交回复
热议问题