Skip to content Skip to sidebar Skip to footer

Using Php Session To Display Status Messages

I'm trying to display a submission status above my contact form, so my plan is to use sessions, but it's not working properly. The form successfully submits, and the page gets succ

Solution 1:

HTML pages will not parse PHP data/syntax unless specifically told to via .htaccess, httpd.conf or some similar server level association methods.

You are trying to display the PHP SESSION data within a HTML page, which is not going to happen until you tell the html page to interpret PHP code.

This StackOverflow question gives you clear guides on how to achieve this.

If your demo.htm is just a HTML page with no ability to handle PHP then you will see output (including all the PHP code) as if it was only HTML.

Example:

demo.html (from your question):

<?php
 session_start();
 ?><!DOCTYPE html><html><head>*stuff*</head><body><pid="status"><?phpif(isset($_SESSION['status'])){
       echo$_SESSION['status'];
  unset($_SESSION['status'];
  }
 ?></p>

This is being treated as HTML and so will produce a mess of output due to the < and > being HTML parser opening and closing tags.

I have also removed the $ from the echo statement as echo is a function not a variable.

Answer :

While the link I give above is useful, it is quickest and easiest to simply rename your demo.htm to demo.php to indicate to the server to parse the page as a PHP page. You will need to update links to the page (such as the form action tag) but it will mean the page will be correctly processed by the server.

Post a Comment for "Using Php Session To Display Status Messages"