Help with the include command

I have a little problem with the include script.

[php]
a.php

<? $var = "apple"; ?>

[/php]
b.php
[php]

<? include ("a.php"); echo $var; ?>

[/php]
This works but this doesn’t…

[php]
a.php

<? $var = "apple"; ?>

[/php]
b.php
[php]

<? include ("http://www.domain.com/a.php"); echo $var; ?>

[/php]

The difference between them is the http://www.domain.com/ is included in the include. I need to know why this does work or how I can include a file which is in a different directory for example…

a.php in root directory
b.php in /php directory and this has the include command in.

Thanks,

This is a good start: http://nl2.php.net/manual/en/function.include.php
And I found this just around the corner: http://phphelp.com/forums/viewtopic.php?t=3308

As far as I know, files included from a remote server have to match certain criteria to be included as an actual PHP script (and even then, I believe they’re being processed on the remote server, rather than on your including server).

You can use the following ways to include a file (where file a.php is being included by file b.php):

[php]
// File a.php in /
// File b.php in /

include (‘a.php’);
include (’/a.php’);

// File a.php in /includes
// File b.php in /

include (‘includes/a.php’);
include (’/includes/a.php’);

// File a.php in /
// File b.php in /processes

include (’…/a.php’);
include (’/a.php’);

// File a.php in /php/includes
// File b.php in /php

include (‘includes/a.php’);
include (’/php/includes/a.php’);

// File a.php in /php
// File b.php in /php/processes

include (’…/a.php’);
include (’/php/a.php’);

// File a.php in /php/includes
// File b.php in /php/processes

include (’…/inclues/a.php’);
include (’/php/includes/a.php’);
include (’…/…/php/includes/a.php’);
[/php]

I know this should be in a new topic but its a little question.

How can i store the page i was on before in a variable? BUT NOT by going back or using javascript:history.go(-1).

I’m not sure if this is php or not. I wouldn’t know what to search in Google.

$_SERVER[‘HTTP_REFERER’] :)

It works, but I just figured out that I need to do it 2 pages ago. so http://www.domain.com/a.php
http://www.domain.com/b.php
http://www.domain.com/c.php - have http://www.domain.com/a.php in a variable.

$_GET, $_POST, $_COOKIE or $_SESSION variables should come in handy here.

Sponsor our Newsletter | Privacy Policy | Terms of Service