We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Omega2+ PHP7 Sessions not working



  • Hello,

    I am not able to get PHP7 Sessions working on my Omega2+, when I run this php script from a browser:
    <?php
    session_start();
    ?>
    I get the following error message:

    Fatal error: Uncaught Error: Call to undefined function session_start() in /www/Sessions/demo_session1.php:2 Stack trace: #0 {main} thrown in /www/Sessions/demo_session1.php on line 2

    I have php7, php7-mod-session, php7-cgi, php7-cli, php7-fastcgi installed. I am able to run other php/html scripts with no problems. When I run phpinfo() in the script (session_start(); commented out) it appears the sessions is enabled... '--enable-session=shared'.

    Any help on this would be greatly appreciated.

    Paul



  • @Paul-Smulders
    What is listed under "list interpreter" in /etc/config/uhttpd ?



  • Thanks for replying Jon, list interpreter is:

    list interpreter ".php=/usr/bin/php-cgi"
    

    Note: the Omega's firmware is 0.1.10 b160

    Best Regards,
    Paul



  • Can you post the code of the demo_session1.php page and also do a phpinfo() and see what it says for session. Also, you could try:

    if (extension_loaded('session')) {
        echo "Session Loaded";
        }
    

    I also see you have php cli installed... are you using it? What happens if you uninstall cli and restart with only cgi installed?



  • Hello Jon,

    I have removed the php7-cli but the result is the same error message as above. The demo_session1.php script is pretty bare-bones:

    ?php
    session_start();
    //phpinfo();

    ?>
    <!DOCTYPE html>
    <html>
    <body>
    <h1> Testing ... Session </h1>
    <?php
    echo "Current script owner is: " . getmypid();
    ?>
    </body>
    </html>

    I have tried the phpinfo() ... without the session_start() ... and it comes back with a lot of info, I'm not sure where to look for session issues ? Also, the getmypid() returns an int and

    if (extension_loaded('session')) {
    echo "Session Loaded";
    }else{
    echo "Session not loaded";
    }

    displays ... "Session not loaded" (when the session_start() is commented out of course).

    My end objective in this is to have php identify the user accessing the file so that I can have the script respond differently depending on the user. Unless there's another way to uniquely identify a user without using session.

    Best Regards,
    Paul



  • The first line should be

    <?PHP
    

    not

    ?PHP
    

    When doing the phpinfo(), just ctrl+f in your browser and search for "session" there should be a whole section if it's installed.

    It seems odd that session not loaded is returned from extension_loaded... it should be loaded regardless if you use it or not.

    Have you tried re-installing the session module with opkg and then restarting with

    /etc/init.d/uhttpd restart
    

    in the command line?



  • Hello Jon,

    Really appreciate your help on this.

    The missing < in <?php was a copying mistake, it's there...

    I've checked the phpinfo() file but there's no section on Sessions,
    just:

    '--enable-session=shared' in the Configure Command section
    Additional .ini files parsed /etc/php7/20_session.ini

    in the standard section....
    session.trans_sid_hosts no value no value
    session.trans_sid_tags a=href,area=href,frame=src,form=
    a=href,area=href,frame=src,form=

    int the Environment section ...
    SCRIPT_NAME /Sessions/sessions.php
    SCRIPT_FILENAME /www/Sessions/sessions.php
    REQUEST_URI /Sessions/sessions.php

    I have removed and re-installed php7-mod-session, rebooted, and performed an uhttpd restart ... to no avail, error message still there when opening page...

    Maybe removing all PHP7 packages and re-installing will resolve this, otherwise ??

    Best Regards,
    Paul



  • if you are creating a php page with the following code:

    <?php
    // Show all information, defaults to INFO_ALL
    phpinfo();
    ?>
    

    and you view the page, and do not have a section named "session" as shown below:
    0_1537307468971_Untitled-1.png

    Go to /usr/lib/php/ ... is there a session.so file in there?

    Unless there is some funky file/folder permission issue here... I really don't know. If you installed session module it should be enabled by default.

    I guess you could try getting rid of everything php and doing an opkg update and then re-install php7 php7-cgi php7-mod-session... I don't know what else to suggest.



  • Hello Jon,
    I've looked into the session.io file and it has a bunch gibber and a message half way through indicating:
    Session is not active
    Cannot call default session handler ss
    php-7.2.9/ext/session/mod_user_class.c
    Parent session handler is not open
    S SS
    and much more (not able to copy it out of Atom editor ....)

    The result of phpinfo() call does not give a section labeled session as you've posted.

    I'm running php7 (7.1.1-1) php-cgi (7.1.1) and php-mod-session (7.2.4-2). I've tried re-installing php7, php-cgi and php7-mod-session and rebooting, no luck. Tried removing and re-installing the above packages all with ver 7.2.9-3 and rebooting ... but then I get a browser error: Bad Gateway
    The process did not produce any response.

    Luckily, I have a firmware back-up on a USB stick so I can restore the Omega2+ to its previous working state (ie my php script is working but not the simple sessions script).

    It appears I'm out of luck with PHP Sessions and the Omega .... I'll have to find another way to identify a user...

    Thanks for the help,
    Best Regards,
    Paul



  • So here is what I did, with an Omega2+ and an arduino2 dock that I keep around for testing.
    This gave me a default Omega-Ware version of VS 0.1.10 b160

    • I did a factory reset on the module by holding down reset for 10s. (Then waited for 5-10 min while it setup)

    • go through setup wizard to set wireless and console using omega-XXXX.local/setup-wizard

    • Install editor and terminal

    • Using terminal command line:
      run opkg update
      run opkg install php7 php7-cgi php7-mod-session

    • Using editor:
      change /etc/config/uhttpd to include the following lines at the bottom of the top section:
      list interpreter ".php=/usr/bin/php-cgi"
      option index_page 'index.php'

    • Using Terminal command line:
      restart server with /etc/init.d/uhttpd restart command

    • Using Editor:
      create new folder /www/phptest/
      create new file /www/phptest/phpinfo.php
      add the following code to phpinfo.php and save it:

      <?PHP
         session_start();
         echo session_id();
         phpinfo();
      ?>
      
    • With your browser (I am using Chrome, with cookies enabled) go to: http://omega-XXXX.local/phptest/phpinfo.php

    I have used this setup on at least 15 different Omega2+ modules and they all worked without issue, please try this and let me know what happens.



  • Hello Jon,

    Thank you very much, followed your instructions and php session is working (was a bit reluctant to perform a factory reset on the Omega... but it was worth it).

    Now I need to restore the old omega's program/files and see if session still works.

    Best Regards,
    Paul



  • No problem, happy you got it working!



Looks like your connection to Community was lost, please wait while we try to reconnect.