Jump to content


Photo

Simple include question?


  • Please log in to reply
5 replies to this topic

#1 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 06 August 2006 - 01:56 AM

I feel stupid for even asking but here we go.

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

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

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

Here is an example.
<?php
include("../includes/constants.php");

$content = "hello world";

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

The test.php
<?php
echo "$content";
?>

if I just use something like this.
include("../test.php");
the content is echoed...?

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

Thanks,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#2 nethnet

nethnet
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 06 August 2006 - 02:28 AM

From the manual:

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.


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.
"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 06 August 2006 - 02:34 AM

I am using php 5. I aready tried using and echo. It echoed the url just fine.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#4 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 06 August 2006 - 03:34 AM

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

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.php
b.php
<?php
/*
There's 4 ways to do it,
-> require("");
-> require_once("");
-> include("");
-> include_once("");
*/
require_once("a.php");
include($url . "c.php");

Hope you understand what I mean.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#5 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 06 August 2006 - 03:46 AM

@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

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#6 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 06 August 2006 - 05:09 AM

Sorry for the late reply, I just went to update my old script.
Hmm... Your welcome mate :)

Helping others is a joyful thing to do

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users