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.


Log in to reply
 

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