This is quite alot of code so bare with me:
index.php
<?php
session_start();
/*
* FUNCTIONS
*/
function content(){
global $type;
global $con;
if($type == "php"){
$new_con = str_replace('#' , '\'' , $con);
$final_con = str_replace('##' , '\"' , $new_con);
eval($final_con);
} elseif($type == "txt"){
echo($con);
} elseif($type == ""){
echo "";
} else {
echo "UR DUMB!";
}
}
/*
* THE SHIZNAT
*/
switch($pg){
// -----------Default--------------------
default:
$type = "txt";
$con = "Welcome ";
$con .= $_SESSION['admin_name'];
$con .= "!<br><br>";
break;
//-----------Admin PAGE------------------------------
case "admin":
$type = "php";
$con = "include(#admin.php#);";
break;
//---------Logout-----------------------------
case "logout":
$type = "txt";
$con = "You have logged out!<br>";
unset($_SESSION['admin_name']);
unset($_SESSION['last_date']);
session_destroy();
break;
}
include("template.html");
?>
admin.php
<?
session_start();
$thedate = date("F jS, Y \@ g:i a");
function loginform(){
echo "<form method=\"POST\" action=\"index.php?pg=admin\">",
"Username: <input type=\"text\" name=\"username\" size=\"15\">",
"<br>",
" Password: <input type=\"password\" name=\"userpass\" size=\"15\">",
"<br>",
"<input type=\"hidden\" name=\"passed\" value=\"yes\">",
"<input type=\"submit\" name=\"login\" value=\"Login\">",
"</form>";
}
if(!isset($_SESSION['admin_name'])){
if(!isset($_POST['passed'])){
echo "Type your username and password below:<br>";
loginform();
} else {
$fp = fopen("admins.txt", "r");
$contents = fread($fp, filesize("admins.txt"));
fclose($fp);
$admininfo = explode("|","$contents");
if(strtolower($_POST['username']) == $admininfo['0'] && md5($_POST['userpass']) == $admininfo['1']){
$fp = fopen("lastdate.txt", "r");
$lastvisitx = fread($fp, filesize("lastdate.txt"));
fclose($fp);
$lastvisitarray = explode("|",$lastvisitx);
$lastvisit = $lastvisitarray['1'];
$fp = fopen("lastdate.txt", "w");
$string .= $admininfo['0'];
$string .= "|";
$string .= $thedate;
$write = fputs($fp, $string);
fclose($fp);
session_start();
$_SESSION['admin_name'] = $admininfo['0'];
$_SESSION['last_date'] = $lastvisit;
} else {
if(strtolower($_POST['username']) !== $admininfo['0']){
echo "<b>The username you specified does not exist!</b>";
$wrongname = "yes";
loginform();
}
if($wrongname !== "yes"){
if(strtolower($_POST['username']) == $admininfo['0'] && md5($_POST['userpass']) !== $admininfo['1']){
echo "<b>The password you entered is incorrect!</b>";
loginform();
}
}
}
}
} else {
echo "Your already logged in you foo!<br>";
}
?>
template.html
<html>
<head>
<style>
a:active, a:link, a:visited{text-decoration:none; font-family:verdana; size:2; color:#000000}
a:hover {text-decoration:underline; font-family:verdana; size:2; color:#000000}
</style>
</head>
<body bgcolor="#E9E9E9" link="#000000" vlink="#000000" alink="#000000">
<p align="center"><font face="Verdana" size="3"><b>Baseball Standings Generator</b></font></p>
<div align="center">
<center>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="900" id="AutoNumber1">
<tr>
<td valign="middle" height="29" align="center">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" id="AutoNumber2" height="17">
<tr>
<td width="65" bgcolor="#0099CC"
onmouseover="style.backgroundColor='#00afea'; style.cursor='hand'; style.border='1 solid #000000'"
onmouseout="style.backgroundColor='#0099cc';" onclick="location.href='index.php'"
width="131" valign="middle" height="17" align="center">
<font face="Verdana" size="1">Main<br>
</font>
</td>
<td width="65" bgcolor="#0099CC" valign="middle" height="17" align="center" onmouseover="style.backgroundColor='#00afea'; style.cursor='hand'; style.border='1 solid #000000'"
onmouseout="style.backgroundColor='#0099cc';" onclick="location.href='index.php?pg=admin'"
<font face="Verdana" size="1">Admin<br>
</font>
</td>
<? if(isset($_SESSION['admin_name'])){
echo "<td width=\"65\" bgcolor=\"#0099CC\" valign=\"middle\" height=\"17\" align=\"center\" onmouseover=\"style.backgroundColor='#00afea'; style.cursor='hand'; style.border='1 solid #000000'\"",
"onmouseout=\"style.backgroundColor='#0099cc';\" onclick=\"location.href='index.php?pg=logout'\"",
">",
"<font face=\"Verdana\" size=\"1\">Logout<br>",
"</font>",
"</td>";
}
?>
</tr>
</table>
</td>
</tr>
<tr>
<td width="896" valign="top"><center><br><font face="Verdana" size="2"><? content(); ?></font></center></td>
</tr>
</table>
</center>
</div>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="900" id="AutoNumber5" height="19">
<tr>
<td width="100%" height="19">
<div align="right"><font face="Verdana" size="1">Copyright © 2004 | <a href="mailto:shawn_kurtz@hotmail.com&subject=Baseball%20Standings%20Pro">
Shawn Kurtz</a> | All Rights Reserved<br>
</font></div>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>
In template.php I have a place where it tests to see if $_SESSION['admin_name'] is set....if it is it add's the option of LOGOUT to the menu if I refresh then it works....but right after I log in it still only has Main and Admin!? please helppppp