• What is the easiest ways to use PHP session

    SapnaVishwas Member

    What is the easiest ways to use PHP session

  • Adelaid Member

    The easy ways of using the PHP session are documented here:
    http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11909-PHP-Sessions-Simpler-Than-You-May-Think.html

    The PHP session_id() function returns a value:
    http://php.net/manual/en/function.session-id.php

    The return value will always be true with respect to isset(), but your release level of PHP may not allow you to test with isset() when your script tests the return value of a function.
    http://php.net/manual/en/function.isset.php

    Can you please tell us in plain language, what are you trying to achieve with this if() statement? The usual way of working with the session would just start the session at the beginning of the script and would never need to test to see if the session had been started!

  • ShikhaTan Member

    If you have session_start() at the top of the page, then you will have a session id. And you have to assign $_SESSION variables after that. There aren’t any automatic $_SESSION variables.

    http://php.net/manual/en/function.session-start.php

  • Adan Member

    If you have to write conditional code to determine whether the session is started or not, there is a design flaw in the application. “Housekeeping” things like setting the error reporting, starting the session, and connecting to the database should always be done unconditionally at the logical top of the application. Often these things are factored out of inline code into a common script that gets brought in with a require_once statement. Then the PHP scripts that build the web pages start like this:

    
    

    And in session.php we have something like this:

    
    

    The session.php script is also a convenient place to store your class and function definitions if you're not using an autoloader.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.
en_USEnglish