LOL I guess that would help...
Main Page:
Code:
<?php
ob_start();
session_start();
include_once('includes.php');
$SQLObj = new SQL;
$SQLObj->DatabaseConnect();
$Recordset1 = $SQLObj->SelectQuery("SELECT servers.servername FROM servers ORDER BY servers.servername ASC");
$totalRows_Recordset1 = $SQLObj->RecordCount($Recordset1);
$Username = "";
$Error = "";
//------------------
// Attempt to login.
//------------------
if (isset($_POST["Submit"])) {
$Username = $_POST["username"];
$Password = $_POST["password"];
//----------------------------------
// Validate the email address first.
//----------------------------------
$ValidateUser = $SQLObj->SelectQuery("SELECT * FROM users WHERE USERNAME='%s'", $Username);
if (count($ValidateUser) <= 0) {
$Error = "<strong>".$_POST['username']."</strong> is not an Authorized User. Please try again.";
} else {
$DBPassword = $ValidateUser[0]["password"];
$NewPassword = $Password;
if ($DBPassword != $NewPassword) {
$Error = "The password provided appears invalid. Please try again.";
} else {
//-- Login successfull --//
$_SESSION["username"] = $_POST["username"];
$_SESSION["password"] = $_POST["password"];
?>
<script language="javascript">
parent.location.href = 'default.php';
</script>
<?php
}
}
}
if(isset($_GET['logout']) && ($_GET['logout'] != "")) {
unset($_SESSION['username']);
unset($_SESSION['password']);
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test page</title>
<link href="test.css" rel="stylesheet" type="text/css" />
<script language="javascript">
function reloadToonframe() {
if(document.servform.servermenu.value == '') {
frames['toons'].location.href = 'server.php';
} else {
frames['toons'].location.href = document.servform.servermenu.value;
}
}
function reloadMainframe(newLoc) {
var loadURL = newLoc;
frames['main'].location.href = loadURL;
}
</script>
</head>
<body>
<iframe frameborder="0" scrolling="auto" src="player.php" name="main" id="main"></iframe>
<iframe frameborder="0" scrolling="Auto" src="server.php" name="toons" id="toons"></iframe>
<div class="headerbox">
<br />WOWRealPlayers.com
</div>
<div class="loginbox">
<form ACTION="default.php" id="login" name="login" method="POST">
<table width="30%" border="1" align="right" cellpadding="0" cellspacing="0">
<tr>
<th colspan="2" scope="row">User Login </th>
</tr>
<tr>
<th width="29%" scope="row">Username</th>
<td width="71%"><input name="username" type="text" id="username" /></td>
</tr>
<tr>
<th scope="row">Password</th>
<td><input name="password" type="password" id="password" /></td>
</tr>
<tr>
<th colspan="2" scope="row"><input type="submit" name="Submit" value="Submit" /></th>
</tr>
<tr>
<td><a class="style2" href="javascript:reloadMainframe('register.php');">Register</a></td>
<td> </td>
</tr>
</table>
</form>
</div>
<div class="menubox">
<form name="servform" method="get">
<select id="servermenu" size="1" onChange="reloadToonframe();">
<option value="">Choose WOW Server</option>
<?php
$a=0;
while($a <= $totalRows_Recordset1) {
printf("<option value=\"server.php?s=%s\">%s</option>", $Recordset1[$a]['servername'], $Recordset1[$a]['servername']);
$a++;
}
?>
</select>
</form>
<br /><a href="default.php">Home</a>
<?php if(isset($_SESSION['username']) && ($_SESSION['username'] != "")) { ?>
<br />
<a href="default.php?logout=y">Logout</a><br />
<a href="javascript:reloadMainframe('addservers.php');">Add/Change Servers</a>
<br />
<?php } ?>
</div>
</body>
</html>
<?php
$SQLObj->DatabaseDisconnect();
?>
now the page loaded into the iframe:
Code:
<?php include_once('includes/includes.php');
$SQLObj = new SQL;
$SQLObj->DatabaseConnect();
$Recordset3 = $SQLObj->SelectQuery("SELECT toonlist.*, users.username FROM toonlist INNER JOIN users ON (users.playerid = toonlist.playerid) WHERE toonlist.playerid = '%d'", $_REQUEST['p']);
$totalRows_Recordset3 = $SQLObj->RecordCount($Recordset3);
$Recordset4 = $SQLObj->SelectQuery("SELECT * FROM images WHERE playerid = '%d'", $_REQUEST['p']);
$totalRows_Recordset4 = $SQLObj->RecordCount($Recordset4);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body bgcolor="#0066CC">
<?php
if (isset($_SESSION['username']) && ($_SESSION['username'] != "")) {
printf("Welcome back, %s! <br /><br />", $_SESSION['username']);
}
if (isset($_REQUEST['p']) && ($_REQUEST['p'] != "")) {
?>
<div align="center">Pictures and info for <?php echo($Recordset3[0]['username']); ?>:</div>
<br />
<p>
<ul>
<?php
$c=0;
while($c<$totalRows_Recordset3) {
printf("<li>%s on %s</li>", $Recordset3[$c]['toonname'], $Recordset3[$c]['servername']);
$c++;
}
?>
</ul>
</p>
<p>
<?php
$d=0;
while($d<$totalRows_Recordset4) {
printf("<img align='middle' src='images/playerimages/%s' /><br />", $Recordset4[$d]['image']);
$d++;
}
?>
</p>
<?php
}
?>
</body>
</html>
and lastly the relevant portions of the class file:
Code:
<?php
class SQL
{
var $LastError;
var $SQL;
function DatabaseConnect()
{
$LastError = "";
//-----------------------------
// Connect to the mysql server.
//-----------------------------
$dbHandle = @mysql_connect('localhost', 'root', '5ansa');
if ($dbHandle == false) {
$LastError = "Unable to connect to the database server: " . mysql_error();
return false;
}
mysql_select_db("test");
return $dbHandle;
}
function DatabaseDisconnect()
{
mysql_close();
}
function SelectQuery($Value)
{
$LastError = "";
$NumArgs = func_num_args();
$CurrentArg = 0;
$SQL = "";
//-----------------------------
// Construct the SQL statement.
//-----------------------------
for ($index = 0; $index < strlen($Value); $index++) {
$first = substr($Value, $index, 1);
$second = substr($Value, $index + 1, 1);
if ($first == "%") {
switch ($second) {
case "%":
$index++;
$SQL .= "%";
break;
case "s":
case "d":
case "f":
$index++;
$CurrentArg++;
if ($CurrentArg > $NumArgs) {
$this->Error = "Expected a variable for placeholder at index " . $index;
return false;
}
$SQL .= func_get_arg($CurrentArg);
break;
default:
$this->Error = "Expected a placeholder type (i.e. %s or %d) at index " . $index;
return false;
}
}
else
$SQL .= $first;
}
$Query = $SQL;
//-----------------
// Execute a query.
//-----------------
$resultTable = @mysql_query($Query);
if ($resultTable == false) {
$LastError = "Unable to execute database query: " . mysql_error();
return false;
}
//-----------------------
// Turn it into an array.
//-----------------------
$resultArray = array();
$recordCount = mysql_num_rows($resultTable);
$fieldCount = mysql_num_fields($resultTable);
for ($index = 0; $index < $recordCount; $index++) {
$row = mysql_fetch_row($resultTable);
for ($fieldIndex = 0; $fieldIndex < $fieldCount; $fieldIndex++) {
$fieldName = mysql_field_name($resultTable, $fieldIndex);
$resultArray[$index][$fieldName] = $row[$fieldIndex];
}
}
//---------------------------------------------
// Close the connection and return the results.
//---------------------------------------------
return $resultArray;
}
function RecordCount($resultArray)
{
return count($resultArray);
}
}
?>
Way more than you needed, but I'd rather overdo it than leave out something I'm missing. The line in red on the iframed page *should* display if the user is logged in, but isn't.
Thanks,
Shot
Bookmarks