Jump to content

Simple include question?


tomfmason

Recommended Posts

I feel stupid for even asking but here we go.

I have a constants.php file that defines the url of my site.

[b]An example of the constants[/b]
[code=php:0]<?php
$url = "http://www.mysite.com"
?>[/code]

when I include this file and try to use it in another include, I am unable to pass any information in a variable.

[b]Here is an example.[/b]
[code=php:0]
<?php
include("../includes/constants.php");

$content = "hello world";

include("$url/test.php");
?>[/code]

[b]The test.php[/b]
[code=php:0]<?php
echo "$content";
?>[/code]

if I just use something like this.[code=php:0]include("../test.php");[/code] the content is echoed...?

Any suggestions as to why this is happening, or a way around it, would be great.

Thanks,
Tom
Link to comment
Share on other sites

From the manual:

[quote] If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper - see Appendix M for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.

Warning

Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if allow_url_fopen is enabled.[/quote]

What version of PHP are you using?

Also, try replacing that include with an echo just to see exactly what string is being used by the include function.
Link to comment
Share on other sites

Take note:
For example, I name it as [b]a.php[/b]
<?php
$url = "http://www.mysite.com"[b];[/b]
?>

If you want to use $url variable on other page, you need to require/include them to the other page.

Let's say, you wanna use it on [b]b.php[/b]
[b]b.php[/b]
[code]<?php
/*
There's 4 ways to do it,
-> require("");
-> require_once("");
-> include("");
-> include_once("");
*/
require_once("a.php");
include($url . "c.php");[/code]

Hope you understand what I mean.
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.