TxanTxan
November 28th, 2004, 06:06 AM
Hi!
I want to use session variables.
In the main page (main.php) I register the variable like this:
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css"/>
<title>Demo</title>
</head>
<body>
<?php
session_start();
$_SESSION['log'] = false;
?>
<div id="container">
<div id="header"><?php require('header.php'); ?></div>
<div id="topnav"><?php require('topnav.php'); ?></div>
<div id="sidenav"><?php require('sidenav.php'); ?></div>
...
Then, in the sidenav.php I look if the log variable is true or false:
<?php
if (!isset($_SESSION['log'])) {
echo("not defined");
}
else{
echo("defined");
}
if($_SESSION['log']==false){ /*not logged in*/
<form method="post" action=info.php?what=login>
<br>Username: <input class="inputStyle" type=text name="username"></br>
<br>Password: <input class="inputStyle" type=password name="password"></br>
<br><input class="submitStyle" type=submit value="Login"></br>
</form>
...
}
else { /*logged in*/
...
}
This sidenav is included in the main.php and it works in this main page. But when I jump to another page that also includes the sidenav.php (for example, when I click the Login button and I go to info.php) the log session variable is not defined. Why it isn't defined in the other files?
Thanks
I want to use session variables.
In the main page (main.php) I register the variable like this:
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css"/>
<title>Demo</title>
</head>
<body>
<?php
session_start();
$_SESSION['log'] = false;
?>
<div id="container">
<div id="header"><?php require('header.php'); ?></div>
<div id="topnav"><?php require('topnav.php'); ?></div>
<div id="sidenav"><?php require('sidenav.php'); ?></div>
...
Then, in the sidenav.php I look if the log variable is true or false:
<?php
if (!isset($_SESSION['log'])) {
echo("not defined");
}
else{
echo("defined");
}
if($_SESSION['log']==false){ /*not logged in*/
<form method="post" action=info.php?what=login>
<br>Username: <input class="inputStyle" type=text name="username"></br>
<br>Password: <input class="inputStyle" type=password name="password"></br>
<br><input class="submitStyle" type=submit value="Login"></br>
</form>
...
}
else { /*logged in*/
...
}
This sidenav is included in the main.php and it works in this main page. But when I jump to another page that also includes the sidenav.php (for example, when I click the Login button and I go to info.php) the log session variable is not defined. Why it isn't defined in the other files?
Thanks