Another form question
Posted: Fri Sep 01, 2006 9:29 am
Another question based on this.....
If my main page, http://www.site.com/index.php, AND my news page, http://www.site.com/news.php, are setup like this.
With the modifications I made to http://www.mysite.com/templates/forms/logon.php
Why do I lose $_SESSION['username'] when I switch better the pages news and main?
I think the session keeps restarting because of the header?
If my main page, http://www.site.com/index.php, AND my news page, http://www.site.com/news.php, are setup like this.
Code: Select all
<?php
include 'templates/header.php';
...
include 'templates/forms/logon.php';
...
include 'templates/footer.php';
?>Code: Select all
<?php
include('config.php');
if(isset($_POST['username'])){
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$username = $_POST['username'];
$password = md5($_POST['password']);
$query = "SELECT * FROM ff_users WHERE username = '" . $username . "' and password = '" . $password . "'";
$result = mysql_query($query);
if (! mysql_num_rows($result)){
echo " <form name=\"login\" method=\"post\" action=\"" . substr($_SERVER['REQUEST_URI'], 1) . "\">
<div id=\"sideform\">
<input type=\"text\" name=\"username\" size=\"15\" class=\"\" maxLength=\"20\">
<input type=\"password\" name=\"password\" size=\"15\" class=\"\" maxLength=\"20\">
<input type=\"submit\" name=\"submit\" value=\"Logon\">
</div>
</form><br><b>Invalid Username or Password</b>";
}
else{
$_SESSION['username'] = $username;
}
}
if(isset($_SESSION['username'])){
echo "<div id=\"sideform\">Welcome, <b>" . $_SESSION['username'] . "</b></div></form>";
}
else{
echo " <form name=\"login\" method=\"post\" action=\"" . substr($_SERVER['REQUEST_URI'], 1) . "\">
<div id=\"sideform\">
<input type=\"text\" name=\"username\" size=\"15\" class=\"\" maxLength=\"20\">
<input type=\"password\" name=\"password\" size=\"15\" class=\"\" maxLength=\"20\">
<input type=\"submit\" name=\"submit\" value=\"Logon\">
</div>
</form>";
}
?>I think the session keeps restarting because of the header?
Code: Select all
<?php
for($index=0; $index<sizeof($toptab_pages); $index++){
if($toptab_pages[$index][page_location] == substr($_SERVER['REQUEST_URI'], 1)){
$page_name = $toptab_pages[$index][page_name];
$page_location = $toptab_pages[$index][page_location];
$page_title = $toptab_pages[$index][page_title];
$page_description = $toptab_pages[$index][page_description];
$page_keywords = $toptab_pages[$index][page_keywords];
$page_author = $toptab_pages[$index][page_author];
$page_class = $toptab_pages[$index][page_class];
break;
}
$page_name = 'Home';
$page_location = 'index.php';
$page_title = 'MySite';
$page_class = 'home';
$page_description = 'MySite: Under Construction';
}
for($index=0; $index<sizeof($navitab_pages); $index++){
if($navitab_pages[$index][page_location] == substr($_SERVER['REQUEST_URI'], 1)){
$page_name = $navitab_pages[$index][page_name];
$page_location = $navitab_pages[$index][page_location];
$page_title = $navitab_pages[$index][page_title];
$page_description = $navitab_pages[$index][page_description];
$page_keywords = $navitab_pages[$index][page_keywords];
$page_author = $navitab_pages[$index][page_author];
$page_class = $navitab_pages[$index][page_class];
break;
}
}
echo " <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
<head>
<meta name=vs_targetSchema content=\"http://schemas.microsoft.com/intellisense/ie5\">
<title>" . $page_title . "</title>
<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">
<meta name=\"description\" content=\"" . $page_description . "\">
<meta name=\"keywords\" content=\"" . $page_keywords . "\">
<meta name=\"author\" content=\"" . $page_author . "\">
<link rel=\"stylesheet\" type=\"text/css\" href=\"andreas02.css\" media=\"screen\" title=\"andreas02 (screen)\" />
<link rel=\"stylesheet\" type=\"text/css\" href=\"print.css\" media=\"print\" />
</head>
<body><a name=\"top\"></a> \n";
?>