简体   繁体   English

Codeigniter重定向不适用于实时服务器,但适用于本地主机

[英]Codeigniter redirect is not working on live server but working in localhost

I am using codeigniter for my project. 我正在为我的项目使用codeigniter。 I have create a foreach loop and I want to redirect after end of the loop. 我创建了一个foreach循环,并希望在循环结束后进行重定向。 It is working on localhost but not in live server. 它可以在localhost上运行,但不能在实时服务器上运行。 Here is my code: 这是我的代码:

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');
        }

    }
}

and here is my htaccess file: 这是我的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>

I tried another solution from stackoverflow, but couldn't get, where is the probleme. 我尝试了stackoverflow的另一种解决方案,但无法解决问题所在。 Please help me. 请帮我。

I didn't check it but seems like this will work : 我没有检查它,但似乎这可以工作:

function redirect_to($location){
  header("Location: $location");
  exit;
}

if(mysql_affected_rows() == 1){
  //success
  redirect_to("index.php");
}

Don't define a default value for an argument and then check for it, just don't give it a default to begin with. 不要为参数定义默认值,然后再检查它,只是不要给它以默认值开头。 Also remove the brackets in the Location: header. 还要删除“位置:”标题中的括号。

I had the same problem of redirect function's. 我有同样的重定向功能的问题。

Then find the file which is addressed in log file and check if there is any space or any unused blank lines 'before and after the php tag .If you find any space then remove it. 然后在日志文件中找到要寻址的文件,并检查php标记前后是否有任何空间或任何未使用的空行。如果找到任何空间,则将其删除。 then your redirect function would be work. 那么您的重定向功能就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 CodeIgniter 中的重定向功能在实时服务器上不起作用,但在 localhost 上运行良好 - Why in CodeIgniter redirect function is not working on live server, but working fine on localhost 会话不在localhost中工作但在实时服务器中工作(Codeigniter) - Sessions not working in localhost but work in live server (Codeigniter) 重定向功能在实时服务器上不起作用。 但是在本地主机上工作 - Redirect function is not working on the live server. But working on localhost 重定向在实时服务器上不起作用 - the redirect is not working on live server 字体可在localhost上使用,但不能在实时服务器上使用 - Fonts working on localhost but not on live server 查询在本地主机上运行,​​但不在实时服务器上 - Query working on localhost but not on live server pathinfo()在本地主机上运行,​​但不在实时服务器上运行 - pathinfo() working on localhost but not on the live server DOMPDF 无法在 codeigniter 中的实时服务器上运行 - DOMPDF not working on live server in codeigniter php header()在本地主机上工作,但在实时服务器上不工作? - php header() working in localhost but not working on live server? 标头在localhost上工作但不在实时服务器上工作 - header working on localhost but not working on a live server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM