Note that there are some explanatory texts on larger screens.

plurals
  1. POCatch session creation error in PHP
    primarykey
    data
    text
    <p>I wanted to be able to catch the error in session creation in PHP. My primary target is to be able to know which causes the problem. Is it because we don't have wrtie access to the folder where the session is written or because we don't have free disk space already.</p> <p>So of course we will start with this.</p> <blockquote> <p>session_start();</p> </blockquote> <p>and from this post <a href="https://stackoverflow.com/questions/6901547/check-if-session-is-set-or-not-and-if-not-create-one">Check if session is set or not, and if not create one?</a> I did try to add </p> <pre><code> if(session_id() == '') { // session has NOT been started session_start(); echo "Session is started"; } else { // session has been started } </code></pre> <p>And to test this I have remove writing permissions for the group and others in /tmp/ by using this command</p> <blockquote> <p>chmod 755 tmp/</p> </blockquote> <p>But base on my test I still see that the session is started. And the funny thing is I can login but when I try to logout I can't. </p> <p>Any insights on how to properly get the reason on session creation error would be greatly appreaciated. Thanks!</p> <p>EDIT:</p> <p>I have tried Frederik's suggestion and done this.</p> <pre><code>try{ // Start session session_start(); echo "Session started. " . session_id(); }catch(Exception $e){ echo "Session not started. " . $e-&gt;getMessage(); } </code></pre> <p>But I still see this </p> <blockquote> <p>Session started. fa505cbf4b232773669008495fd08b9f</p> </blockquote> <p>even if I have remove write permission to /tmp already. It seems that the try catch was not able to properly catch the problem.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload