Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Including a page that already has includes in it
Old 07-11-2010, 05:28 PM Including a page that already has includes in it
Skilled Talker

Posts: 83
Trades: 0
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 Code:
<?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($rate3'.''');
}

if (
$member == 1) {
    
$rate = ($level*$addrate+1);
    
$rate number_format($rate3'.''');
}

if (
$member == 9) {
    
$rate = ($level*$addrate+1);
    
$rate number_format($rate3'.''');
}

?>
stats.php here:
PHP Code:
<?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 Code:
<?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!
Smudly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-11-2010, 05:32 PM Re: Including a page that already has includes in it
Extreme Talker

Posts: 246
Trades: 3
In stats.php, you could set a variable like
PHP Code:
$stats true
before including any scripts.

Then if you want to NOT include something, you can check $stats to see if it was included from stats.php or not.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by CouponGuy; 07-11-2010 at 05:35 PM.. Reason: I can't read.
CouponGuy is offline
Reply With Quote
View Public Profile
 
Old 07-12-2010, 06:38 AM Re: Including a page that already has includes in it
Kelpie's Avatar
Skilled Talker

Posts: 82
Name: Andrew
Location: SW Scotland
Trades: 0
Alternatively, don't include rates.php in the stats page.
Instead have the code you want both pages to use as a separate file, and have rates.php and stats.php include that file
Kelpie is offline
Reply With Quote
View Public Profile
 
Old 07-12-2010, 08:43 AM Re: Including a page that already has includes in it
Skilled Talker

Posts: 54
Trades: 0
you can also make the code you want to include in both rates.php and stats.php as a function probably in a separate file may be called functions.php and include that functions.php file whenever you want to call function to make use of the code. hope it helps.
kani alavi is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Including a page that already has includes in it
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.69628 seconds with 12 queries