Missing PHP Session in .html file


I'm trying to migrate a Webshop to a new Webserver. It is working perfectly fine on the old Webserver, however, when I try to login at the Webshop (index.html) it returns to the homepage, not logged in as the Session Variable is empty. Then I noticed, when I opened another Site called request.php) the Session Variable was set and I was logged in. So I tried several things, I renamed the index.html to index.php and the session was there.

My question is now: Can I get the Session in .html files, too (as on the previous Webserver) or do I have to rename all my .html files?

Note: The index.html file contains php code as well and is parsed as php, just the session variable is empty.

Thanks in advance for every answer!


if you are using a Apache Server, try add this to the config file.

AddType application/x-httpd-php .html


You need to set a handler in your web server to treat html files as php files.


The files need to be renamed to have a .php extension on them, even if they include html. Simply include your php code before the html starts, like so:

<?php //code goes here ?> <html> <body> //etc...

This way, you can load up your session variable and any other PHP variables you need, then they'll be accessible in the html as well.

If you have several pages that will need the same thing (session variable), you could put the session code into a php file, something like 'session.php'. Then, at the top of every page you're converting from html to php, put this code at the top:

<?php require_once("session.php"); ?>

Now all of your pages will have access to the same information, and it helps to cut down on the code too.


AddType application/x-httpd-php .html

In your .htaccess file will do the job, still I believe it's rather <strong>unsafe</strong> to do it :)


  • Shell Script for renaming and relocating the files
  • Syntax error in Update statement against Access database (using OleDbCommandBuilder)
  • React Native + Redux: What's the best and preferred navigation?
  • How can I extract results of aggregate queries in slick?
  • Ionic 2 storage is not cleaning up on uninstall - Only for signed APK
  • preg_replace Double Spaces to tab (\\t) at the beginning of a line
  • Ajax Loaded meta Tags
  • Debugging ASP.NET on a built-in web server suddenly stops
  • Xamarin Forms - UWP Fonts
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • ILMerge & Keep Assembly Name
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Updated Ionic CLI but shows previous version (Windows)
  • Symfony2: How to get request parameter
  • Upload files with Ajax and Jquery
  • Weird JavaScript statement, what does it mean?
  • Adding custom controls to a full screen movie
  • How do you troubleshoot character encoding problems?
  • Do I've to free mysql result after storing it?
  • Why winpcap requires both .lib and .dll to run?
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • How do I rollback to a specific git commit
  • Arrays break string types in Julia
  • Is there a mandatory requirement to switch app.yaml?
  • How to format a variable of double type
  • A cron job substitute?
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • json Serialization in asp
  • log4net write single file for each call to log.info
  • Getting error when using KSoap library to consume .NET web services
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • unknown Exception android
  • Busy indicator not showing up in wpf window [duplicate]
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • reshape alternating columns in less time and using less memory
  • How to Embed XSL into XML
  • Conditional In-Line CSS for IE and Others?