Smudly Posted July 11, 2010 Share Posted July 11, 2010 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! Link to comment https://forums.phpfreaks.com/topic/207445-including-a-page-that-already-has-includes-in-it/ Share on other sites More sharing options...
BillyBoB Posted July 12, 2010 Share Posted July 12, 2010 include_once() would be what you need for the connect page and I would set a variable in the stats page to let the rates page know not to include admin. rates.php here: <?php session_start(); /// Include Admin Page Here /// if(!$_GET['admin']) include('inc/admin.php'); include_once('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_once('inc/connect.php'); include ('rates.php?admin=false'); $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> I usually build a functions or classes page which takes cares of connecting to the database and checking members permissions. so then you just include_once('functions.php'); and you have it to use. Good luck! Have fun. Link to comment https://forums.phpfreaks.com/topic/207445-including-a-page-that-already-has-includes-in-it/#findComment-1084623 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.