Jump to content

Archived

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

smy101

Including a seperate Variable file

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="myemail@mysite.com";
$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!

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.