phphtmlsession

PHP sessions with HTML


I have a website which uses PHP and HTML pages, I want to create a session which stores a username from the login page. But the login pages are php and the next pages are html.

Is this a problem or can I just add a small statement of php into the html page saying

 <?PHP session_start();
$_session['loginid']=$_post['username'];
?>

Or am I doing it wrong?

This is the first time i've used sessions and they confuse me a little.

thanks for any help.


Solution

  • If you have access to your apache configuration, or a simple .htaccess file, you can tell Apache to handle php code inside of an .html file. You can do this by creating an .htaccess file (remember the . (dot) as the first character in that filename) on the document root of the site (probably public_html/) and putting this into it:

    # Add this to public_html/.htaccess file
    AddHandler application/x-httpd-php .html
    AddHandler application/x-httpd-php .htm
    

    You should be able to reload the html page and your PHP code (from Michael Matthews answer) will run great.