Jump to content

Archived

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

tomfmason

Simple include question?

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

Share this post


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

Share this post


Link to post
Share on other sites
I am using php 5. I aready tried using and echo. It echoed the url just fine.

Share this post


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

Share this post


Link to post
Share on other sites
@hackerkts

I understand and I don't know why I didn't think of that before..lol

I realy appreciate all of your help,
Tom

Share this post


Link to post
Share on other sites
Sorry for the late reply, I just went to update my old script.
Hmm... Your welcome mate :)

[i]Helping others is a joyful thing to do[/i]

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.