php include()带参数实现方法

具体方法详解

举例:假设在 index.php 中需要调用 inc.php?para=3 ,

inc.php

 代码如下 复制代码

<?php     echo $_GET['para']; ?>

下面的写法是无法得到正确结果的:

index.php

 代码如下 复制代码
<?php     include dirname(__FILE__).'/inc.php?para=3'; ?>

稍微变通一下,把$_GET变量在include之前定义,则可以正常运行:
index.php

 代码如下 复制代码
<?php     $_GET['para'] = 3     include dirname(__FILE__).'/inc.php; ?>

如果php.ini中开启了allow_url_include功能,则可以使用include url的方式:
index.php

 代码如下 复制代码

<?php     include 'http://www.yoururl.com/inc.php?para=3'; ?>

设置方法:php.ini中,找到如下行,改为On:

; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
allow_url_include = On

不过为了保证安全性,大部分的服务器都将allow_url_include 功能关闭,那样就只能视情况而定了。

时间: 2024-09-20 21:46:12

php include()带参数实现方法的相关文章

C#线程调用带参数的方法

在 .NET Framework 2.0 版中,要实现线程调用带参数的方法有两种办法. 第一种:使用ParameterizedThreadStart. 调用 System.Threading.Thread.Start(System.Object) 重载方法时将包含数据的对象传递给线程. 使用 ParameterizedThreadStart 委托不是传递数据的类型安全的方法,因为 System.Threading.Thread.Start(System.Object) 方法重载接受任何对象. 这

C#创建线程带参数的方法_C#教程

1.无参数线程的创建 Thread thread = new Thread(new ThreadStart(getpic)); thread.Start(); private void showmessage() { Console.WriteLine("hello world"); } 2.带一个参数的线程 使用ParameterizedThreadStart,调用 System.Threading.Thread.Start(System.Object) 重载方法时将包含数据的对象传

ASP代码实现301重定向及带参数的方法

  由于改版需要,烈火网的一个栏目需要做301重定向,这是很久以前的烈火导航下的一个搜索,使用的是asp语言,但是蜘蛛喜欢,因此不能删除,只好写一个301重定向,但是原来的很多网址都是有参数的,例如TAG标签,形式如:liehuo_tag.asp?q=%C1%D2%BB%F0%CD%F8. 研究了一下,解决了301重定向带参数的问题,特来向大家分享,欢迎朋友多支持烈火网. 代码如下: <% if request.ServerVariables("HTTP_HOST")="

在命令行下运行PHP脚本[带参数]的方法_php技巧

创建一个简单的文本文件,其中包含有以下PHP代码,并把它保存为hello.php: 复制代码 代码如下: <?php echo "Hello from the CLI"; ?> 现在,试着在命令行提示符下运行这个程序,方法是调用CLI可执行文件并提供脚本的文件名: #php phphello.php 输出Hello from the CLI 使用标准的输入和输出 你可以在自己的PHP脚本里使用这三个常量,以接受用户的输入,或者显示处理和计算的结果.要更好地理解这一点,可以看

ObjectDataSource控件的select方法如何应用类似select(sql)带参数的方法

问题描述 比如我有一个Result类,其中有一个Result.SearchResult(strSQL)的select方法,这个类还有更新,删除方法,我现在已经指定了更新,删除方法,而且Result.SearchResult(strSQL)也以指定,其中的strSql参数指定为None,strSQL是通过组合选择拼接而成的,我想让ObjectDataSource在程序中指定strSQL,完整的代码如何写?this.ResutlObjectDataSource.SelectParameters["s

C#带参数运行方法

比如aa.exe -autoaa.exe -main两组后缀,要求分别运行aa的某个线程,比如aa.exe -auto打开from1,aa.exe -main打开from2由于需要修改Program的Main方法,需要更加谨慎,因为一个结构清晰的Main对于后期维护是一个很好的帮助.以下的代码将解析参数,构造启动窗体,启动窗体三个逻辑分割为三个方法 Code 1 static class Program 2     { 3         /// <summary> 4         ///

C#,往线程里传带参数的方法

问题描述 List<SyncTableInfo>listTables=GetSyncTables();listTables=listTables.OrderBy(n=>n.Sort).ToList();string[]dataSource=new[]{"etl_scn","etl_aisien","erp-xy"};Thread[]thread=newThread[dataSource.Count()];for(inti=0;i

get方式带参数请求方法

直接贴代码,JS代码如下: var opt ={ url : urlConfig.interfaceUrl.project_interfaceConfig.getProjectSets, type : 'GET', data : { hid : hospId } }; alert(JSON.stringify(opt)); ri.getData(opt,function(data){ alert(1111); alert(JSON.stringify(data)); //$scope.proje

Python - 带参数的方法

import math class Point: def move(self, x, y): self.x = x self.y = y def reset(self): self.move(0, 0) def calculate_distance(self, other_point): return math.sqrt( (self.x - other_point.x)**2 + (self.y - other_point.y)**2) # how to use it: point1 = Po