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="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!
Link to comment
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?
Link to comment
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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.