在传递参数时从另一个 php 文件调用 php 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5389619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:14:31  来源:igfitidea点击:

calling php file fron another php file while passing arguments

php

提问by su03

i need to call a php inside another php file and pass some arguments also. how can i do this?? i tried

我需要在另一个 php 文件中调用一个 php 并传递一些参数。我怎样才能做到这一点??我试过

include("http://.../myfile.php?file=$name");
  • but gives access denied. i read like v must not set allow_url_open to OFF.
  • 但拒绝访问。我读起来像 v 不能将 allow_url_open 设置为 OFF。

if i write like

如果我这样写

$cmd = "/.../myfile.php?file=".$name";
$out =exec($cmd. " 2>&1");
echo $out;
  • gives error as /.../myfiles.php?file=hello: no such file or directory.
  • 给出错误为 /.../myfiles.php?file=hello: 没有这样的文件或目录。

how can i solve this???

我该如何解决这个问题???

回答by Bj?rn

You don't have to pass anything in to your included files, your variables from the calling document will be available by default;

您不必向包含的文件传递任何内容,默认情况下,调用文档中的变量将可用;

File1.php

文件1.php

<?php

$variable = "Woot!";
include "File2.php"; //if in the same folder

File2.php

文件2.php

<?php
echo $variable;

回答by Charlie

the location in your code is incorrect:

您代码中的位置不正确:

$cmd = "/.../myfile.php?file=".$name;

回答by MiPnamic

you can include file over http only if the allow_url_fopenis set to TRUE, and the same parameter allow you to pass variables to the files...

仅当allow_url_fopen设置为 TRUE 时,您才能通过 http 包含文件,并且相同的参数允许您将变量传递给文件...

回答by Stefan Gehrig

You should not include files via HTTP connection - that's almost always a serious security problem.

您不应该通过 HTTP 连接包含文件 - 这几乎总是一个严重的安全问题。

If you must do this, you have to set allow_url_includeandallow_url_fopento ONbut neither is a recommended procedure.

如果您必须这样做,您必须设置allow_url_includeandallow_url_fopentoON但两者都不是推荐的程序。