Jump to content

Accessing $_SESSION variables on html.


m0v0nage

Recommended Posts

My website is made up of html files. Recently I realized i needed php. I edited the .htaccess file so that it looks like this:

 

AddType application/x-httpd-php .htm .html

 

This allowed me to execute php on any html page. But one thing I am having trouble with is accessing Session information. I do this on an html page:

 

$name = $_SESSION['Name'];

 

with the session_start() at the top (I know I did that correctly). It can't seem to find the name. I do the same on a .php page, and it works. But why can't an html page access the Session variables? It can echo things and run other php functions, but why not the SESSION info.

Link to comment
https://forums.phpfreaks.com/topic/191008-accessing-_session-variables-on-html/
Share on other sites

Why not try a debugging test?

one.html:

<?php
   session_start();
   $_SESSION['Name'] = 'foo';
   header('Location: two.html');
?>

two.html

<?php
   session_start();
   echo '<pre>';
   print_r($_SESSION);
?>

 

Does it return anything? Does the PHP code turn up in the source?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.