By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,515 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,515 IT Pros & Developers. It's quick & easy.

include() in if...else statement?

P: 1
When a user logs in my website, it references a character file. In that character file, there is a variable defined, $guild; which if true, has to include a file with guild information.

So, in the profile page where a user views his/her own information, I need to include the guild file, but since there are more than one guild, I have to include a certain guild file.

I have this so far.

Expand|Select|Wrap|Line Numbers
  1. <?php include('../character_library/'. $_SESSION['name'] .'.inc'); ?>
  2.   <?php
  3.  
  4.     if ($guild == false) {
  5.  
  6.     } else {
  7.  
  8.     include('../character_library/guild_library/'$guild'.inc');
  9.     }
  10. ?>
  11.  
The first part includes the character file, which is in a session when they log in, and the second part needs to include a guild file if they belong to one.

So, in this case, the character does belong to a guild, let's say, the alpha guild.

In the character file it says

Expand|Select|Wrap|Line Numbers
  1. $guild = "alpha";
  2.  
And I have a file on my server called alpha.inc.

When I insert the statement, and later on in the page I try to access $guildmaster which is in the alpha.inc file, it just hangs, and does NOTHING.

Thanks for any help you can give me, I'm a bit of a begginner. :-D

-galadrix
Jun 23 '06 #1
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,916
[php]
include('../character_library/guild_library/'$guild'.inc');
[/php]

I think that you have a small error in this line, I think you need to use the concatinate string operator . , or at least I would so that it looks like

[php]
include('../character_library/guild_library/' . $guild . '.inc');
[/php]

Additionally if the page requires the page I suggest that instead of include you use require. The are 4 functions that includes other files into the current script

include
include_once
require
require_once

The differences are the require functions will produce an error and abort the script if they fail (making it rather obvious). The _once functions (as opposed to the other ones) only include the given file if it has not already been included (useful for files that start sessions and such like).
Jun 25 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.