tomfmason Posted August 6, 2006 Share Posted August 6, 2006 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]<?phpinclude("../includes/constants.php");$content = "hello world";include("$url/test.php");?>[/code][b]The test.php[/b][code=php:0]<?phpecho "$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 Quote Link to comment Share on other sites More sharing options...
nethnet Posted August 6, 2006 Share Posted August 6, 2006 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.WarningWindows 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. Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 6, 2006 Author Share Posted August 6, 2006 I am using php 5. I aready tried using and echo. It echoed the url just fine. Quote Link to comment Share on other sites More sharing options...
hackerkts Posted August 6, 2006 Share Posted August 6, 2006 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. Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 6, 2006 Author Share Posted August 6, 2006 @hackerktsI understand and I don't know why I didn't think of that before..lolI realy appreciate all of your help,Tom Quote Link to comment Share on other sites More sharing options...
hackerkts Posted August 6, 2006 Share Posted August 6, 2006 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] 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.