Jump to content
flydev 👊🏻

Strange behavior with Session and debug mode [SOLVED]

Recommended Posts

Hi everyone,

[edit: do not loose your time reading this post, I solved it by disabling cache in the Pages2Pdf module... sorry 😓]

 

I do not know if I should post on the Pages2Pdf thread or here. Mods, feel free to move the post.

 

Since three days I am scratching my head :goberserk: to understand a weird thing happening with $session and $config->debug used in conjunction with Pages2Pdf module. For information, I tested it on a fresh install of ProcessWire 3.0.96 with PHP-7.0.28 and Pages2Pdf-1.1.7 (domain: http://session.sites.sek/). I will try to explain what is going on.

 

What I am trying to achieve :

In a template, I need to set some sessions variables which are then echo'd in the PDF document.

(on the test installation, the basic-page template (page /about/?pages2pdf) serve the PDF, the home and sitemap template set the session variable.)

 

The problem :

From the template sitemap, I set a variable: $session->setFor('pdf', 'myvar', 'Session set from Sitemap template');

From the template home, I set a variable: $session->setFor('pdf', 'myvar', 'Session set from Home template');

Then in the PDF default template, I echo the session variable: <p>Session: <?= $session->getFor('pdf', 'myvar'); ?></p>

 

Now I turn ON debug mode ($config->debug = true) :

  1. Then I navigate to  "http://session.sites.sek/home/" and the session variable "myvar" is set to "Session set from Home template".
  2. Then I navigate to  "http://session.sites.sek/sitemap/" and the session variable "myvar" is set to "Session set from Sitemap template".
  3. Now I want my PDF document, so I navigate to "http://session.sites.sek/about/?pages2pdf=1" and I get my PDF document with the right session var : "Session set from Sitemap template"

For the moment, nothing special happen. Everything work great. We are in debug mode.

 

Now I turn OFF debug mode ($config->debug = false) :

  1. Then I navigate to  "http://session.sites.sek/home/" and the session variable "myvar" is set to "Session set from Home template".
  2. Then I navigate to  "http://session.sites.sek/sitemap/" and the session variable "myvar" is set to "Session set from Sitemap template".
  3. Then I navigate back to "http://session.sites.sek/home/" and the session variable "myvar" is set back to "Session set from Home template".
  4. Now I want my PDF document - as expected, the "myvar" should be set to "Session set from Home template" - so I navigate to "http://session.sites.sek/about/?pages2pdf=1" and here the problem happen. Instead of echoing  "Session set from Home template" in the PDF document, the phrase "Session set from sitemap" is echo'd (the last value recorded before switching from debug ON).

 

 

I made two small screencasts to show the issue :

  • DEBUG ON (Everything is OK)

5aaf7b8ba8d50_debugON.thumb.gif.c07799d63007b59db4f7b908d05b7ea5.gif

 

  • DEBUG OFF

5aaf7ba8d6bfa_debugOFF.thumb.gif.fca12333be0dfbd982bf7bca93e433d6.gif

 

 

I am missing something ? EDIT: YES, you are dumb!

Why it is working with debug mode ON and not vice-versa ?

Is there someone who already spotted this strange behavior ?

Is there a PHP settings which should be modified ?

 

====================================================

Edit:

I needed to post just to figure myself that Pages2Pdf cache the document when $config->debug is false.

😬😬😬

 

Edited by flydev
solved
  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By derelektrischemoench
      Hi guys,
      I'm facing a somewhat strange issue here which I can't quite wrap my head around. 
      I have a PW site in development which runs on three machines simultaneously, one staging server which is accessible as a preview instance for my customer, my PC and my laptop. 
      I have three completely identical settings on each of the three machines (same apache version, same php version, same codebase, same database); however on my PC I am unable to log into the backend. I get no error message or anything, when I try to login; i just get redirected to the login  page. I have already enabled database driven sessions (I enabled them on my laptop, then I dumped the database and copied it to my pc); I have cleared the cache directory; I cleared the sessions in the database; I cleared my browser caches, I tried different browsers, all to no avail; I am unable to login when using my pc, the instances all have the same .htaccess.
      Is there something I'm missing here or does anyone have a clue as to what my issue here might be? I'm using processwire 3.0.123
      Thanks for any input, greetings
      derelektrischemoench
       
      //edit: I've noticed something interesting; despite the directories of my web folders being the same layout; when I open the admin page i get a 404 on the processwire/ resource in the networks panel of chrome; on my laptop I get a  200.... I guess this is where my problem is; but why?
       
       
    • By derelektrischemoench
      Hi guys,
      I'm facing a somewhat strange issue here which I can't quite wrap my head around. 
      I have a PW site in development which runs on three machines simultaneously, one staging server which is accessible as a preview instance for my customer, my PC and my laptop. 
      I have three completely identical settings on each of the three machines (same apache version, same php version, same codebase, same database); however on my PC I am unable to log into the backend. I get no error message or anything, when I try to login; i just get redirected to the login  page. I have already enabled database driven sessions (I enabled them on my laptop, then I dumped the database and copied it to my pc); I have cleared the cache directory; I cleared the sessions in the database; I cleared my browser caches, I tried different browsers, all to no avail; I am unable to login when using my pc, the instances all have the same .htaccess.
      Is there something I'm missing here or does anyone have a clue as to what my issue here might be? I'm using processwire 3.0.123
      Thanks for any input, greetings
      derelektrischemoench
       
       
    • By Peter Knight
      How do you guys handle large session tables when sessions are being recorded to the database?
      I notice one of my sites has a session table of over 14MB 
      Am I missing a way in the Admin or a module to auto-remove any sessions older than X days?
      Thanks
       
    • By helmut2509
      In my PW-Application there is currently no session timeout.
      I want to set the user session to 60 minutes which means that after 60 minutes of inactivity the user will be redirected to the homepage.
      so I added the following entry to my config.php:
      $config->sessionExpireSeconds = 120; (120 seconds is just for testing).
      But after five minutes of inactivity I am still logged in, there is no redirection.
      Is there anything wrong or did I miss something?
      In php.ini I have the entry:
      session.cookie_lifetime = 3600
    • By August
      Hi again, after trying pages2PDF, RockPDF and mpdf I'm not sure which of them I should use. Of course, there is also wirePDF.
      I merged mpdf with rockPDF, add a footer and a page in Landscape and that works, like in the code-snippet below but be am I on the right way?
      After that I tried a couple of times rendering an image. Nothing happend, the same with Pages2PDF too. I also copied an Image-URL within processwire and tried further getting an Image within the PDF-Document, but it still display only the red marked placeholder.
      I simply would like create an PDF on click from some Pages including the Images.
      Are there special requirements on Debian 10 with Apache and php 7.3 using Processwire 3.0.123.?
      Is there a guide that I didn't found?
      Is somebody out there who has a similar issue solved and would you be so kind to explain?
       
      $pdf = $modules->get('RockPdf'); $mpdf = $pdf->mpdf; # $mpdf->showImageErrors = true; $pdf->set('SetHeader', 'header text'); $mpdf->AddPage('L'); # $mpdf->Image(urlencode('site/assets/files/1845/image-2.275x200.jpg'), 0, 0, 210, 297, 'jpg', '', true, false); $pdf->set('SetFooter', ' <table width="100%"> <tr> <td width="33%">{DATE j.m.Y}</td>        <td width="33%" align="center">{PAGENO}/{nbpg}</td> <td width="33%" style="text-align: right;">whatever</td> </tr> </table>'); $pdf->show(); // generate pdf  
×
×
  • Create New...