Jump to content


Photo

Including a seperate Variable file


  • Please log in to reply
5 replies to this topic

#1 smy101

smy101
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 18 September 2006 - 08:34 PM

Ok, I'm pretty sure what I'm trying to do is simple b/c forever ago when I started learning PHP, I think I had it.

Now, I'm catching hell, so someone please help and I'll dance at your wedding.

Here's the scenario:

I have my main page, which we'll call "main.php" for simplicity.

I also have a seperate file for my common variables, we'll call it "vary.php".

What I'm trying to do is include "vary.php" into "main.php" so that I can echo the variables in "main.php" but be able to change the "vary.php" file if need be.

So, lets say "vary.php" looks like this:
<?php
$email="myemail@mysite.com";
$phone="555-555-5555";
$fax="555-555-5555";
?>

Somewhere in "main.php" I try to call the $email variable like so: 
<?php
echo"Email:";  echo"$email";
?>

However, it does not recognize the variable, and only shows "Email:              "

Which tells me it's not reading my included "vary.php" file with the variables in it.

The way I tried to do it was just like the other files I have included, like so:
<?php
include("http://www.mysite.com/php/pages/vary.php");
?>

The other files on the "main.php" (such as "navigationbar.php" and "footer.php") work fine, but this one doesn't.

So, my question is, how do I include (or whatever function I need to use) in order to have a seperate file for my standard variables, and be able to echo them on the "main.php" file?


1 Cookie to the first person that can help.

Thanks in advance!

#2 Devil_Banner

Devil_Banner
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 18 September 2006 - 08:37 PM

Hi,

I'm new at this myself.. ;but maybe you should try a "require" instead of "include" for your variable file
Hope this helps.


#3 smy101

smy101
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 18 September 2006 - 08:49 PM

Hi,

I'm new at this myself.. ;but maybe you should try a "require" instead of "include" for your variable file
Hope this helps.


Hi, thanks for the suggestion.  I tried that, but I get the same thing.  Any other suggestions?

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 18 September 2006 - 09:11 PM

Do not use the full URL to include file that reside on your server. Just use the local file path:
<?php include('vary.php'); ?>

Ken

#5 smy101

smy101
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 18 September 2006 - 09:24 PM

Do not use the full URL to include file that reside on your server. Just use the local file path:

<?php include('vary.php'); ?>

Ken


That did it.  If you don't mind me asking (if you know), why does it behave that way?

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 18 September 2006 - 09:41 PM

When you use the full URL, the PHP processor is invoked to process the PHP script, what is returned is the output of that script. When you use the local path, the raw text is included and then processed.

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users