I am using PHP to check for $_SESSION variables at the top of an HTML page. Here is my code:
<?php require('sessions.class.php');
$session= new session();
$session->start_session('_s',false);
if (!isset($_SESSION('session_id'))){
header(location:'login.html');
}
?>
<!DOCTYPE html>
Everything seems to work until the Object Operator (->) is reached. It’s like the server views this as the PHP closing tag. The text after -> is echoed at the top of the webpage.
This is similar to the question asked here:
why-php-tag-is-closing-on-user
But the OP did not go into the solution with much detail.
Browser= Mozilla
Any help would be appreciated. Thanks!
The problem is probably that you are trying to run PHP code in an html document which is not possible. The < of the PHP opening tag is recognised as the start of an html tag and therefore the code after the first > is output as text, since it is interpreted as the closing of the html tag.
If you want to use PHP, make it a .php file and echo the html. Better yet you want to separate your logic (PHPcode) and markup (html) in separate files as much as possible.
Search for ‘separating PHP and html’
To get you started