0

更新:

当用户访问我的网站时,我使用 .htaccess 将用户重定向到包含所有这些文件的特定文件夹 (/var/www/html/test)。.htaccess 看起来像这样

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (?!^test(/.*|)$)^(.*)$ /test/$1 [NC,L]
</IfModule>

当我将所有文件移至 /var/www/html 并评论 .htaccess 行时。iphone 上的会话开始工作...我不知道为什么.. 有没有办法用 .htaccess 解决这个问题?

---- 更新结束 -----

我有一个调用用户登录函数的 ajax 函数,如果用户/密码正确,它会登录用户。它适用于台式机、笔记本电脑、三星 s3 手机,但不适用于 IPHONE!似乎没有在$this->session->set_userdata('current_email', $email);IPHONE 上设置会话,因此将用户重定向回登录页面。我猜这可能是因为 iphone safari cookie 被自动禁用或类似的东西。解决此问题的最佳方法是什么,以便它可以在手机上使用?

阿贾克斯:

$.ajax({
                url: site_url+"/user/login/"+email,
                type: "post",
                data: 'password='+password+'&email='+email,
                success: function(response){    
                    if(response == "success"){
                      window.location.href = site_url+"/user/invites";
                    }else{
                      alert("Password is not valid");
                    }   
                },  
                error: function(){
                }   
            }); 

/user/login php codeigniter 函数

public function login($email)
        {

                $password = $this->input->post('password');

                if($email != NULL){

                        $this->load->helper('string');
                        $this->load->model('user_model');
                        $this->load->library('session');

                        $user_status = $this->user_model->check_status($email, $password);

                        if (is_array($user_status) && $user_status['is_active']) {

                                $this->session->set_userdata('current_email', $email);
                                $this->session->set_userdata('user_id', $user_status['id']);
                                $this->session->set_userdata('unique_id', $user_status['unique_id']);
                                $this->session->set_userdata('is_active', 1);

                                echo "success"; die();
                        }

                } die();

        }

/用户/邀请

 public function invites($unique_id = NULL)
        {

                if($this->session->userdata('current_email') != FALSE){

                        $data['unique_id'] = $this->session->userdata('unique_id');
                        $data['current_email'] = $this->session->userdata('current_email');

                        if($data['unique_id']){

                                $data['invited_users'] = $this->user_model->get_invited_users($this->session->userdata('user_id'));

                                $data['user_details'] = $this->user_model->get_user_details($this->session->userdata('user_id'));

                        $this->template->write_view('header', 'templates/header2', $data);
                        $this->template->write_view('content', 'invites', $data);

                        // Render the template
                        $this->template->render();

                }else{ 
                        redirect('welcome/index/1','refresh');
                }
4

2 回答 2

0

I can suggest an alternative: use the database as session handler.

You just need to enable it in the application/config/config.php file:

$config['sess_use_database'] = TRUE;

You need a table to store the saved sessions, the manual suggests using this schema:

CREATE TABLE IF NOT EXISTS  `ci_sessions` (
    session_id varchar(40) DEFAULT '0' NOT NULL,
    ip_address varchar(45) DEFAULT '0' NOT NULL,
    user_agent varchar(120) NOT NULL,
    last_activity int(10) unsigned DEFAULT 0 NOT NULL,
    user_data text NOT NULL,
    PRIMARY KEY (session_id),
    KEY `last_activity_idx` (`last_activity`)
);

Other than this, you don't need to do anything, all the needed queries are handled by CI automatically, no change to be done in your actual code.

UPDATE:

A search on google led me to this CI forum thread (and this SO answer). The cause might be safari caching the AJAX request, so you need to add a timestamp to the url and the issue should be resolved. Example:

var timestamp = new Date().getTime();    
$.ajax({
     url: site_url+"/user/login/"+email+"?"+timestamp, // Or use '/' instead of '?'
于 2013-03-29T22:23:16.660 回答
0

Is the ajax call sent to an external domain ?

If so, this might have something to do with security issues. See: http://drupal.org/node/918194

I have only dealt with this problem in IE, I don't know if this could happen on iOS.

So try adding the following on the ajax receiving side script:

<?php
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'); 
?>

Note: make sure this header is put on all necessary pages and it occurs at the very beginning of your script.

于 2013-04-08T09:55:19.217 回答