PHP Require and Include GET

前端 未结 4 607
清酒与你
清酒与你 2021-01-13 05:39

I would like to require a file but also pass GET variables through the url, but when I write:

         


        
相关标签:
4条回答
  • 2021-01-13 06:19

    It is not necessary to pass the variables to the new file, because by including the new file the variables are maintained. Remember that $ _GET is an array, and it can be modified within the script.

    <?php
       $_GET['name'] = "savagewood";
       require_once("myfile.php");
    ?>
    

    On this case, $_GET['name'] is accesible from the "myfile.php"

    0 讨论(0)
  • 2021-01-13 06:26
    <?php
    $getVarsArray = $_GET;
    $postVarsArray = $_POST;
    /* n number of variables and lines of code*/
    include('script-a.php');
    ?>
    

    Now in script-a.php has access to $getVarsArray and $postVarsArray and if in any case you are in doubt you can use $GLOBALS to access any variable throughout the life cycle of a script. But using global variables is a sin. :)

    0 讨论(0)
  • 2021-01-13 06:37

    variables will be available as normal you do not have to pass like this.

    $name='savagewood';
    require_once("myfile.php");
    

    $name will be available in myfile.php

    0 讨论(0)
  • 2021-01-13 06:40

    I think I have got a perfect solution to your problem. You can use implode function of PHP. But I would strongly recommend doing Shakti Singh's code.

    SOLUTION CODE

    echo implode(file('http://path-to-your-site/your-dir/myfile.php?name=savagewood'));
    
    0 讨论(0)
提交回复
热议问题