SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to find out programmatically if sessions are enabled

    Hi folks,

    Been meaning to ask this one for ages. Does anyone know of a way to detect if sessions are enabled on a server?

    phpinfo() has a single enabled/disabled setting showing very simply if it's enabled (Session Support: enabled/disabled) but I can't find a way to access this value through PHP.

    Any ideas?
    A.P.

    generatedata.com - free JS/PHP/MySQL random test data generator.
    Form Tools - free PHP/MySQL form processor.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    I've never seen a server with sessions off or disabled and if they are get a new host.

    But there is no means to turn sessions on or off in php.ini maybe if they put session_start in the disabled functions list.

    Disabling sessions would be the most stupid thing any host could possibly do.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AtomicPenguin View Post
    Hi folks,

    Been meaning to ask this one for ages. Does anyone know of a way to detect if sessions are enabled on a server?

    phpinfo() has a single enabled/disabled setting showing very simply if it's enabled (Session Support: enabled/disabled) but I can't find a way to access this value through PHP.

    Any ideas?
    I've never run into the situation where sessions were disabled. If you absolutely needed it though, I do not think there is a way to get this "Value", but I would instead feed phpinfo() into $var then do regex on that to get your value
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  4. #4
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah - it's very rare, but I need to check for it in the code (it's for an open source app). I think the regexp option is probably the best... crappy, though!

    Thanks guys -
    A.P.

    generatedata.com - free JS/PHP/MySQL random test data generator.
    Form Tools - free PHP/MySQL form processor.

  5. #5
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AtomicPenguin View Post
    Yeah - it's very rare, but I need to check for it in the code (it's for an open source app). I think the regexp option is probably the best... crappy, though!

    Thanks guys -
    Why do you need to check in the code? Have you actually run into an environment where sessions were disabled? You basically can't run any developed php software in that case. I can't imagine such a scenario!
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    As there is no way to turn sessions off in php.ini how do they turn it off? Well I shouldn't say that too loud there is a way but you have to compile PHP from source and use "--disable-session" but the chance of running into this in the wild? None I can promise you that there is no server your users are going to be on that has session turned off.

    I'm sure the only time it will be is by a hobbyist but I'm sure that one kind of person would be smart enough to know that he needs to turn sessions on before he could use any major application.

    My verdict, don't worry about it, it is not worth it. And don't do the regex thing that would be a very big performance hit.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •