[英]Why in CodeIgniter redirect function is not working on live server, but working fine on localhost
[英]Codeigniter redirect is not working on live server but working in localhost
我正在為我的項目使用codeigniter。 我創建了一個foreach循環,並希望在循環結束后進行重定向。 它可以在localhost上運行,但不能在實時服務器上運行。 這是我的代碼:
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的另一種解決方案,但無法解決問題所在。 請幫我。
我沒有檢查它,但似乎這可以工作:
function redirect_to($location){
header("Location: $location");
exit;
}
if(mysql_affected_rows() == 1){
//success
redirect_to("index.php");
}
不要為參數定義默認值,然后再檢查它,只是不要給它以默認值開頭。 還要刪除“位置:”標題中的括號。
我有同樣的重定向功能的問題。
然后在日志文件中找到要尋址的文件,並檢查php標記前后是否有任何空間或任何未使用的空行。如果找到任何空間,則將其刪除。 那么您的重定向功能就可以了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.