Hello,
I have a page called rates.php, that calculates the rate a user earns credits on my website. Inside this rates page, I've included my connect.php page to connect to the database, and also included admin.php which check if the user is an admin. If they are not an admin, it redirects them to the member's page. I am trying to include this rates.php page inside my stats.php page. Inside the stats page I need to do a calculate to determine the user's rate, and echo it out to the screen.
Now here is the issue. If I include rates.php, it is going to include the admin.php & connect.php pages. This is going to cause problems. How do I include only the code after my includes inside my rates.php page? I need it to ignore the admin.php page and connect.php page only when it is included inside stats.php
Any suggestions?
The code is show below:
rates.php here:
<?php
session_start();
/// Include Admin Page Here ///
include('inc/admin.php');
include('inc/connect.php');
$user = $_SESSION['username'];
$sql = mysql_query("SELECT * FROM `users` WHERE `username` ='".$user."'");
$row = mysql_fetch_assoc($sql);
$sql2 = mysql_query("SELECT * FROM `userstats` WHERE `username` ='".$user."'") or die(mysql_error());
$row2 = mysql_fetch_assoc($sql2);
$member = $row['member'];
$level = $row2['level'];
$addrate = .005;
if ($member == 0) {
$rate = ($level*$addrate+.50);
$rate = number_format($rate, 3, '.', '');
}
if ($member == 1) {
$rate = ($level*$addrate+1);
$rate = number_format($rate, 3, '.', '');
}
if ($member == 9) {
$rate = ($level*$addrate+1);
$rate = number_format($rate, 3, '.', '');
}
?>
stats.php here:
<?php
session_start();
if(isset($_SESSION['username'])){
$username = $_SESSION['username'];
include('inc/connect.php');
include ('rates.php');
$statssql = mysql_query("SELECT * FROM `userstats` WHERE `username`='$username'");
$row = mysql_fetch_assoc($statssql);
}
else{
header("Location: index.php");
}
?>
<html>
<head>
<title>Stats</title>
<link rel="stylesheet" type="text/css" href="styles/stats.css" />
</head>
<body>
</body>
</html>
admin.php here:
<?php
// Include this file for Admin Only Pages
//session start and get variable
session_start();
$user = $_SESSION['username'];
include('inc/connect.php');
//query
$get = mysql_query("SELECT * FROM users WHERE username='$user'");
while ($row = mysql_fetch_assoc($get))
{
$admin = $row['member'];
}
if ($admin!=9)
header('Location:http://www.mysite.com/index.php');
?>
Also, if there is a better way to check if the user is an admin, rather than including the admin.php page, please let me know.
Thanks!