简体   繁体   English

会话变量未保存在iPhone上

[英]session variable is not being saved on the iphone

UPDATE: 更新:

I was using .htaccess to redirect users to a specific folder (/var/www/html/test) that had all these files when they accessed my website. 我使用.htaccess将用户重定向到一个特定的文件夹(/ var / www / html / test),当他们访问我的网站时,该文件夹包含所有这些文件。 The .htaccess looked like this .htaccess看起来像这样

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

When I moved all the files to /var/www/html and commented the .htaccess lines.. The sessions on iphone started working... I have no idea why.. Is there a way to fix that with .htaccess? 当我将所有文件都移到/ var / www / html并注释了.htaccess行时。.iPhone上的会话开始工作了...我不知道为什么。.是否可以用.htaccess修复该问题?

---- End Of Update ----- ----更新结束-----

I have an ajax function that calls a user login function and if the user/password are correct, it logs in the user. 我有一个ajax函数,该函数调用用户登录功能,如果用户名/密码正确,它将登录用户。 It works on the desktop, laptop, samsung s3 phones but NOT on the IPHONE! 它可以在台式机,笔记本电脑,三星s3手机上使用,但不能在IPHONE上使用! The $this->session->set_userdata('current_email', $email); $this->session->set_userdata('current_email', $email); seem not to set the session on the IPHONE therefore redirecting user back to login page. 似乎未在IPHONE上设置会话,因此将用户重定向回登录页面。 I am guessing maybe that's because iphone safari cookies are disabled automatically or something like that. 我猜这可能是因为iphone Safari Cookie被自动禁用或类似的原因。 What's the best way to go around this so it works on the phone? 解决此问题的最佳方法是什么,使其可在手机上使用?

ajax: 阿贾克斯:

$.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 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();

        }

/user/invites /用户/邀请

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

I can suggest an alternative: use the database as session handler. 我可以建议一种替代方法:将数据库用作会话处理程序。

You just need to enable it in the application/config/config.php file: 您只需要在application / config / config.php文件中启用它:

$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. 除此之外,您无需执行任何操作,所有需要的查询均由CI自动处理,无需对实际代码进行任何更改。

UPDATE: 更新:

A search on google led me to this CI forum thread (and this SO answer ). 在google上进行的搜索将我带到了这个CI论坛线程 (以及这个SO答案 )。 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. 原因可能是野生动物园缓存AJAX请求,因此您需要在网址中添加时间戳记,并且该问题应得到解决。 Example: 例:

var timestamp = new Date().getTime();    
$.ajax({
     url: site_url+"/user/login/"+email+"?"+timestamp, // Or use '/' instead of '?'

Is the ajax call sent to an external domain ? Ajax调用是否发送到外部域?

If so, this might have something to do with security issues. 如果是这样,这可能与安全性问题有关。 See: http://drupal.org/node/918194 请参阅: http//drupal.org/node/918194

I have only dealt with this problem in IE, I don't know if this could happen on iOS. 我只在IE中处理过此问题,不知道这是否会在iOS上发生。

So try adding the following on the ajax receiving side script: 因此,请尝试在ajax接收方脚本中添加以下内容:

<?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. 注意:确保此标头放在所有必要的页面上,并且出现在脚本的开头。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM