Jump to content

Including a seperate Variable file


smy101

Recommended Posts

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:
[code]<?php
$email="[email protected]";
$phone="555-555-5555";
$fax="555-555-5555";
?>[/code]

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

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:
[code]<?php
include("http://www.mysite.com/php/pages/vary.php");
?>[/code]

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!
Link to comment
https://forums.phpfreaks.com/topic/21191-including-a-seperate-variable-file/
Share on other sites

[quote author=Devil_Banner link=topic=108540.msg436776#msg436776 date=1158611830]
Hi,

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

[/quote]

Hi, thanks for the suggestion.  I tried that, but I get the same thing.  Any other suggestions?
[quote author=kenrbnsn link=topic=108540.msg436791#msg436791 date=1158613882]
Do not use the full URL to include file that reside on your server. Just use the local file path:
[code]<?php include('vary.php'); ?>[/code]

Ken
[/quote]

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.