search

Home  >  Q&A  >  body text

php - How to set new session_id when there is cookie passing session_id

App interface development, user data is stored in the session. I thought the app did not have cookies. Now I don’t know that the app has the same cookie mechanism as the browser. The app request interface brings a token (actually it is session_id). Now it is The app passes the session_id through cookie and post, and if the cookie passes the session_id, the sessio data can be obtained by manually setting the session_id. I want to be able to manually set session_id to obtain session data without modifying the server configuration or disabling cookies.

    if($_REQUEST['token']){
        session_destroy();
        if($_REQUEST['token']){
            session_id($_REQUEST['token']);
        }
        session_start();
    }
大家讲道理大家讲道理2768 days ago778

reply all(1)I'll reply

  • PHPz

    PHPz2017-05-31 10:35:08

    It should not be native development, but loading webview, otherwise it has nothing to do with cookies, and loading webview is no different from opening it in a browser.
    But it should be feasible to add tokens. I feel like you should add the above judgment to the request base class, so that the data passed by the token should be the main one.

    if($_REQUEST['token']){
        //session_destroy();//这个不应该存在吧,因为token中的session id很有可能与cookie中的session id是一样的,如果直接销毁了,你指定session_id也没什么作用了,或者先判定下如果不一样再销毁
        if($_REQUEST['token']){    
            session_id($_REQUEST['token']);
        }
        session_start();
    }

    reply
    0
  • Cancelreply