我正在使用header(Location:"http:\\example.com\enrollments\export");
实际上我的要求是我想在另一个文件中执行http:\ test.com \ enrollments \ export.php链接但是在执行此文件后它不会重定向到http:\ test.com \ enrollments \ export。它将留在www.test.com/test.php。
实施例: -
<?php
header('Location: http://example.com/enrollments/export');
?>
if(isset($data) && $data != ''){
foreach ($data as $key=>$enrollment):
$array1[] = array($enrollment['Enrollment']['created'], $enrollment['Enrollment']['last_name'], $enrollment['Enrollment']['first_name']
);
endforeach;
}
$list1 = array(
array('Sign Date', 'Last Name', 'First Name'))
;
$list = array_merge_recursive($list1, $array1);
$fp = fopen(WWW_ROOT.'excelimport/test/'.'Report_'.date('Y_m_d H:i:s').'.xls', 'w+'); //echo WWW_ROOT;
$f = 'Report_'.date('Y_m_d H:i:s').'.xls';
foreach ($list as $fields) {
fputcsv($fp, $fields, "\t", ' ');
}
答案 0 :(得分:1)
在test.php中创建一个带有href本身的链接只需用href传递一个参数www.test.com/test.php?export=1
在test.php中
if(isset($_GET['export']) && $_GET['export']){
include_once("enrollments/export.php");
}
答案 1 :(得分:0)
而不是:
header('Location: http://test.com/enrollments/export');
使用
include "export.php" #assuming that export.php and test.php are in the same directory
这将运行 export.php ,而不会破坏 test.php 中的执行流程,也不会重定向。这是您案例中最简单的解决方案!
答案 2 :(得分:-1)
你可以使用curl http://www.php.net/manual/en/curl.examples.php
<?php
$curl = curl_init('http://example.com');
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
echo $result;
?>