i wanna start a session per user from the time they login. i'm learning so i wanna write this myself. So, if i use a class to generate the page a member logs into, can i assume i have to $_POST the session id from page to page or is there a way i can do that in the class? I am afraid when generating new pages that the class will generate a new session id per instance of the class and i don't want that. here is the class i am using(basic i know), and then the code for the page created from it.
page_class.php
<?php
// Page class
class Page {
// Declare a class member variable
var $page;
// declare session variable
var $PHPSESSID;
// The constructor function
function Page()
{
$this->page = '';
}
// Generates the top of the page
function addHeader($title)
{
$this->page .= <<<EOD
<html>
<head>
<title>$title</title>
</head>
<body>
<table width="800" border="1" cellspacing="2" align="center">
<tr>
<td colspan="2"><p>
<h1 align="center">$title</h1>
</td>
</tr>
EOD;
}
// add navigation
function addNav($page1, $page2, $page3, $page4, $page5)
{
$this->page .= <<<EOD
<tr>
<td align='center' colspan='2'>
<a href='$page1.php'>About Us</a> / <a href='$page2.php'>Contact</a> / <a href='$page3.php'>Register</a> / <a href='$page4.php'>Login</a> / <a href='$page5.php'>home</a>
</td></tr>
EOD;
}
// Adds some more text to the page
function addContent($content)
{
$this->page .= <<<EOD
<td>$content</td>
</tr>
EOD;
}
// adds an image
function addImage($attribute, $image, $height, $width)
{
$this->page .= <<<EOD
<tr>
<td>
<div align='$attribute'><p><img src='../images/$image.jpg' height='$height.px' width='$width.px'><p>
</td>
EOD;
}
// Generates the bottom of the page
function addFooter($year, $copyright)
{
$this->page .= <<<EOD
<tr><td colspan="2">
<div align="center">© $year $copyright</div>
</td></tr></table>
</body>
</html>
EOD;
}
// Gets the contents of the page
function get()
{
return $this->page;
}
}
?>
index.php created from page class
<?php
session_start();
// does session_start() carry the sess_id from page to page or
// do i need to $_POST it from page to page???????
$username = $_SESSION['username'];
$password = $_SESSION['password'];
// members only area
if ($_POST['logged'] = true) {
echo "<b>Members Only Area</b><p>";
require_once 'page_class.php';
// Instantiate the Page class
$webPage = new Page();
// Add the header to the page
$webPage->addHeader('Know Your Enemy');
// add menu
$webPage->addNav(about, contact, register, login, page);
// add image
$webPage->addImage(center, me, 200, 100);
// Add something to the body of the page
$webPage->addContent("<p align='center'>Welcome $username</p>\n");
// Add the footer to the page
$webPage->addFooter(date('Y'), 'Shamrock Productions LLC');
// Display the page
echo $webPage->get();
} else {
$_POST['logged'] = !true;
header("Location: http://localhost/test/login.php");
}
?>