Php 如何仅执行页面URL并重定向到另一个页面?
我想执行一个URL,然后页面将重定向到请求的标题位置。但页面不能重定向。我的上一页显示在这里 请参阅我的代码- example.phpPhp 如何仅执行页面URL并重定向到另一个页面?,php,redirect,Php,Redirect,我想执行一个URL,然后页面将重定向到请求的标题位置。但页面不能重定向。我的上一页显示在这里 请参阅我的代码- example.php <?php function test() { $aa = 'good morning'; //file_get_content('http://localhost/DemoProject/test.php'); $ch = curl_init('http://localhost/DemoProject/test.php');
<?php
function test() {
$aa = 'good morning';
//file_get_content('http://localhost/DemoProject/test.php');
$ch = curl_init('http://localhost/DemoProject/test.php');
curl_exec($ch);
return $aa;
}
$text = test();
header('location:http://www.google.co.in/search?q='.urlencode($text));
?>
在test.php
文件中,我编写了一个带有生成pdf文件附件的pdf生成代码和电子邮件功能。我只想要http://localhost/DemoProject/test.php
execute
当我运行example.php
文件时。该页面将重定向到http://www.google.co.in/search?q=good+上午
这是显示当前页面的test.php
数据
如何仅执行URL而不检索任何数据?尝试在header()语句之后添加exit语句,这将使代码看起来像
<?php
function test() {
$aa = 'good morning';
//file_get_content('http://localhost/DemoProject/test.php');
$ch = curl_init('http://localhost/DemoProject/test.php');
curl_exec($ch);
return $aa;
}
$text = test();
header('location:http://www.google.co.in/search?q='.urlencode($text));
exit;
?>
下面是PHP文档,说明添加exit将停止所有其他代码执行并重定向到URL。
另外,请确保在调用header()之前没有写入输出,也就是说,在header()之前不会回显或出现可能输出的空行。通过设置选项
CURLOPT_RETURNTRANSFER
$ch = curl_init('http://localhost/DemoProject/test.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
谢谢你的回答。:)