smy101 Posted September 18, 2006 Share Posted September 18, 2006 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]<?phpecho"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]<?phpinclude("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! Quote Link to comment Share on other sites More sharing options...
Devil_Banner Posted September 18, 2006 Share Posted September 18, 2006 Hi, I'm new at this myself.. ;but maybe you should try a "require" instead of "include" for your variable fileHope this helps. Quote Link to comment Share on other sites More sharing options...
smy101 Posted September 18, 2006 Author Share Posted September 18, 2006 [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 fileHope this helps.[/quote]Hi, thanks for the suggestion. I tried that, but I get the same thing. Any other suggestions? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted September 18, 2006 Share Posted September 18, 2006 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 Link to comment Share on other sites More sharing options...
smy101 Posted September 18, 2006 Author Share Posted September 18, 2006 [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? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted September 18, 2006 Share Posted September 18, 2006 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.