How to Get a Session File in PHP

How to Get a Session File in PHP thumbnail
Include a login form to provide your users with personal data.

PHP sessions allow you to generate Web page content specific to users' session IDs and provide persistent access to that session data. Create a session file on your server to hold information related to the session. Sessions are often created after a username and password validation. Once your user logs in and the session is started, she may visit other Web pages. The data will still be available to her under various conditions for a given period of time without the necessity of logging in again.

Instructions

    • 1

      Open your PHP program inside an HTML, text or PHP editor.

    • 2

      Type the code to create the session file after your login script, using the "session_start" function. If the user passes authorization, direct the browser to the user page. If the authorization fails, send the user back to the login page.

      if ( !$auth ) {

      header( 'Location: http://www.mysite.com/login.php' );

      exit;

      } else {

      session_save_path('tmp/');

      session_start(); // start session

      header( 'Location: http://www.mysite.com/userpage.php' );

      }

      The "session_save_path" method sets the session file server path..

    • 3

      Save the PHP file. Use an FTP application to transfer it to your server for testing.

Related Searches:

Resources

  • Photo Credit Hemera Technologies/Photos.com/Getty Images

Comments

Related Ads

Featured