我有abc.php和def.php文件。例如,我想从abc.php中调用def.php。我找到了include()方法,但我不想def。 php在后台激活。我希望浏览器根据def.php的html-php代码重新绘制页面。激活另一个php文件中的php文件
任何想法?
我有abc.php和def.php文件。例如,我想从abc.php中调用def.php。我找到了include()方法,但我不想def。 php在后台激活。我希望浏览器根据def.php的html-php代码重新绘制页面。激活另一个php文件中的php文件
任何想法?
你可能在谈论重定向。
你可以通过发出位置标题来实现。
请注意,这必须在任何内容发送到浏览器之前运行,因此它必须在页面上显示任何内容之前运行。如果您显示一些文本并然后发送位置标题,它将不起作用,因为标题必须始终在内容之前。
header('Location: def.php');
这会告诉浏览器重定向到def.php。
希望它有帮助!
谢谢你的答案。但是,我有很多内容,我发送到浏览器在abc.php之前redirect = | – 2012-03-24 20:59:07
为此您将需要JavaScript。 在Google上浏览一下或者在StackExchange上提出另一个关于更多细节的问题,关于使用JavaScript在新窗口中打开一个新页面。 – Teekin 2012-03-25 12:42:01
您可以返回的def.php
这里的内容是一个例子:
页:def.php
<?PHP
//do many things, but do not echo or print anything
$output ="<div> all the codes</div>"; // collect the markup like this
return $output; // return the output but still do not echo or print
?>
页页次:abc.php
//do its own processing
$myDefPageOutput = include("def.php");
//This will only get the values of the return statement
//Now user $myDefPageOutput wherever you want and redraw the page
谢谢Starx.But abc.php有很多内容(字符串,表单,链接)。我只想用def.php重新绘制页面标记取决于abc.php中的条件。我猜这段代码会添加内容def到abc内容的下面。我对不对? – 2012-03-24 20:56:57
@SedatKURT,不是真的,它将def.php的内容添加到变量中,并且可以使用你喜欢的位置。回声在顶部或底部,它的你的选择 – Starx 2012-03-24 21:00:52
嗯,但在同一时间有没有在网页上abc的内容? – 2012-03-24 21:26:18
要在运行背景 ? – safarov 2012-03-24 12:12:59
[执行从另一个文件的PHP](http://stackoverflow.com/questions/1346708/executing-php-from-another-file) – Stefan 2012-03-24 12:15:02
http://php.net/manual/en/function.http-redirect。 php参考这个 – 2012-03-24 12:24:01