Sessions and uploadify

后端 未结 11 2030
无人及你
无人及你 2020-12-02 19:18

I\'m using uploadify, and i can\'t set sessions in my php files, my script looks like this:

    $(\"#uploadify\").uploadify({
        \'uploader\'       : \'         


        
相关标签:
11条回答
  • 2020-12-02 19:37

    you cannot solve this because uploadify has own session ID which is created by flash player. In other words the flash player access the uploadify script as a new user and gets a new session. The only way you can solve this is to pass current page session_id through post to the uploadify script.

    0 讨论(0)
  • 2020-12-02 19:37

    I found the solution, if your backend script needs authentication and redirects you will get the 302 problem - simply create a new controller or script that does not need authentication.

    Then, from the code above change 'script' : '/admin/uploads/artistsphotos', To 'script' : '/admin/uploads-unprotected/artistsphotos/id=< ?php echo md5($theUserSessionId); ?>',

    Then in your backend script simply check the id that was passed and authenticate the upload request with a different strategy.

    0 讨论(0)
  • 2020-12-02 19:39

    I'm currently having a similar problem with uploadify + PHP sessions.

    Using error_log() I can monitor that when the uploadify flash app sends the file data up to the server, it passes the correct session_id to the upload script:

    'scriptData' : { 'session_id' : session_id },

    (session_id set earlier: var session_id = '';)

    So, that lets me check that yes, the session id for my pages and the session id for the uploadify script are in fact the same.

    But, when the script runs and I start the session by:

    session_id($session_id); session_start();

    Somehow ALL the session data is destroyed (I've also been setting session data into an array so I can refresh and watch the data grow with each request, then when I use uploadify, it's wiped).

    I have no clue on how to debug this :/

    edit: suhosin may be destroying the session:

    http://www.uploadify.com/forum/viewtopic.php?f=7&t=2062

    0 讨论(0)
  • 2020-12-02 19:41

    I found a solution which is far easier to implement, especially if you already have a session-oriented PHP backend for login, etc.:

    just write the following code in the jQuery statement:

    'script'    : '/upload.php?<?= session_name(); ?>=<?= session_id(); ?>',
    

    which will magically attach your current session name and your session id.

    0 讨论(0)
  • 2020-12-02 19:41

    put a label hide in the document with id = "id_usuario_logueado" and value $_SESSION[id]

    just write the following code in the jQuery statement:

    'scriptData': {'id_usuario':$('#id_usuario_logueado').text()},
    

    later in php

    $id_usuario = $_POST['id_usuario'];

    0 讨论(0)
  • 2020-12-02 19:43

    Usually the session ID won't be read from POST. You could do this:

    $_COOKIE['PHPSESSID'] = $_POST['PHPSESSID'];
    session_start();
    
    0 讨论(0)
提交回复
热议问题