Search code examples
phpgoogle-chromesession-cookiesacrobatpdf-form

Getting same session from browser into Adobe


I'm working with PDF Forms and I've been able to send the information to a php script which correctly gets the data field values when I send it as an HTML.

My problem is that I would like to know who sent the form by making the user log in in a page I made. When he's connected I can't get his id because the session and cookies stay within the browser and when I send the form by clicking the submit button the Adobe program gets another PHPSESSID and Cookies are also different.

Is there a way to get both within the same machine? I tried identifying by using the IP but it's not a good way since they could be behind a NAT.

Is there a way for Adobe Acrobat to get the same Session Instance or Cookie Chrome sets when I'm logged in the website?


Solution

  • Instead of trying it this way why not use a php library to create a pdf with a hidden field "session" containing the session id?

    Load a specific session in PHP:

    session_id($_POST['my_hidden_value']);
    session_start();
    // $_SESSION is available now
    

    Keep in mind when passing a session with a file it can be hijacked and a session will be deleted after some period of time, so you should consider generating a "download key" linked to the user, add it to the document and use that to figure out which user submitted the form.
    This way even when someone has the download key, he can't login as this user.

    /e: You can manipulate a PDF using fpdf file like this:

    session_start();
    
    // Load fpdm
    require('fpdm.php');
    
    // Create a random session id
    $SessionID = md5($_SESSION['userid'] . time());
    
    // Store it in some database here
    
    // Fields to fill out
    $fields = array(
        'my_hidden_value' => $SessionID
    );
    
    // Load pdf, fill field and display it to user
    $pdf = new FPDM('template.pdf');
    $pdf->Load($fields, false);
    $pdf->Merge();
    $pdf->Output();
    

    Source (modified): http://www.fpdf.org/en/script/ex93.pdf
    FPDF: http://www.fpdf.org