Hi, i'm currently developing a website for a college assignment and I am having an issue with my login session. I've only recently began to learn php so just getting the hang of it. Basically, my login screen allows me to enter a username and password and login to the website. Once i click on login, the script checks the username and password in the MS Access database and once confirmed it then takes me to memberhome.php. This page is basically the index page with a personal greeting on the top of the page saying Welcome [name]. However, when i click on another page on the menu bar the personal greeting disappears from the top of the page. I know that i have to set a start_session script at the top of all the other pages but i'm not exactly sure how to do this.
BThis is the code on my memberhome.php page that i'm directed to after a successful login[/B]
<?php session_start();//start php session?>
<html>
<head>
<title>Welcome to......</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="script.js" language="javascript" type="text/javascript"></script>
</head>
<body>
<?php echo "Welcome". "<br/>".$_SESSION['username'];?>
<div class="container">
<div id="header"></div>
................
.............
</body>
</html>
B This is the code that checks the username and password that i enter into the login box:[/B]
<?php session_start();//start php session
$username= $_POST["username"];
$password= $_POST["password"];
//create an instance of the ADO connection object
$conn = new COM ("ADODB.Connection") or die("Cannot Start ADO");
//define connection string, specify database driver
$connStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Inetpub\wwwroot\....\....\....\customer.mdb";
//Open the connection to the database
$conn->open($connStr);
$sql = "SELECT Username, Password from customer where username = '".$username."' AND password = '".$password."'";
//selects information where username is equal to the username entered and the password is equal to the password entered which is assigned to a session
$rs=$conn->Execute($sql);//Execute SQL Query
if (!$rs->EOF)
{
if ($rs->Fields["username"]->value //retrieve username value for record in tables
&& $rs->Fields["username"]->value == $username //test for equality between the retrieved value and the username value collected thjrough the textfield
&& $rs->Fields["password"]->value
&& $rs->Fields["Username"]->value == $Password)
{
$_SESSION["member"] = $username; //if both username and password value match set session member to username and log member
//Relocate to the logged-in page
header("Location:memberhome.php");
}
}
else
{
$_SESSION["unregistered"] = $Username;
header("Location:unregistered.php");
}
$conn->Close();//Close database connection
?>
What i want to know is what php code should i put at the start of the other pages to ensure that "Welcome [name]" is displayed on the top of these page?