首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Codeigniter重定向在实时服务器上不起作用,但在本地主机上起作用

问Codeigniter重定向在实时服务器上不起作用,但在本地主机上起作用
EN

Stack Overflow用户
提问于 2017-07-24 13:48:39
回答 2查看 1.8K关注 0票数 0

我正在为我的项目使用codeigniter。我已经创建了foreach循环,并希望在循环结束后重定向。它可以在本地主机上运行,但不能在实时服务器上运行。下面是我的代码:

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
<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中的另一个解决方案,但无法获得,问题在哪里。请帮帮我。

EN

回答 2

Stack Overflow用户

发布于 2017-07-24 13:52:57

我没有检查它,但看起来这会起作用:

代码语言:javascript
复制
function redirect_to($location){
  header("Location: $location");
  exit;
}

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

不要为参数定义默认值,然后再检查它,只是不要一开始就给它一个默认值。同时删除Location:页眉中的括号。

票数 0
EN

Stack Overflow用户

发布于 2018-03-16 16:28:05

我在重定向函数中也遇到了同样的问题。

然后找到在日志文件中寻址的文件,并检查是否有空格或任何未使用的空行‘在php标签.If之前和之后,您找到任何空格,然后删除它。然后,您的重定向函数将工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45273415

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档