我正在为我的项目使用codeigniter。我已经创建了foreach循环,并希望在循环结束后重定向。它可以在本地主机上运行,但不能在实时服务器上运行。下面是我的代码:
public function __construct()
{
parent::__construct();
$this->load->helper('url');
}
public function my_function() {
$config['upload_path'] = 'my_file_destination/';
$config['allowed_types'] = 'txt';
$this->load->library('upload', $config);
if ($this->upload->do_upload('text_file')) {
$upload_data = $this->upload->data();
function curl_load($number_url){
curl_setopt($ch=curl_init(), CURLOPT_URL, $number_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
$number_url = base_url()."my_file_destination/".$upload_data['file_name'];
$file_content = curl_load($number_url);
$mobileNO = explode(',', $file_content);
$smsFormat = "Hello, this is a test message from LMS. Test Multiple sms. Let me know if you get it.";
function httpGet($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
$user = "my_username";
$pass = "my_password";
$sid = "api_key";
$url = "my_sms_api";
$SMSText = urlencode($smsFormat);
$i = 1;
foreach($mobileNO as $mobile_no){
$mobile_no = '88'.$mobile_no;
echo httpGet("my_sms_api/plain?user=$user&password=$pass&sender=$sid&SMSText=$SMSText&GSM=$mobile_no&type=longSMS&datacoding=1");
$sms_data = array(
'mobile_no' => $mobile_no ,
'message' => $SMSText ,
'sms_date' => date('d/m/Y')
);
$this->db->insert('tbl_custom_sms', $sms_data);
$i++;
}
if($i = count($mobileNO)+1){
redirect('customsms/index');
}
}
}下面是我的htaccess文件:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
# Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>我尝试了stackoverflow中的另一个解决方案,但无法获得,问题在哪里。请帮帮我。
发布于 2017-07-24 13:52:57
我没有检查它,但看起来这会起作用:
function redirect_to($location){
header("Location: $location");
exit;
}
if(mysql_affected_rows() == 1){
//success
redirect_to("index.php");
}不要为参数定义默认值,然后再检查它,只是不要一开始就给它一个默认值。同时删除Location:页眉中的括号。
发布于 2018-03-16 16:28:05
我在重定向函数中也遇到了同样的问题。
然后找到在日志文件中寻址的文件,并检查是否有空格或任何未使用的空行‘在php标签.If之前和之后,您找到任何空格,然后删除它。然后,您的重定向函数将工作。
https://stackoverflow.com/questions/45273415
复制相似问题