Forum Moderators: coopster

Message Too Old, No Replies

SSI include works, PHP include doesn't

         

gchristen

4:15 am on Feb 6, 2010 (gmt 0)

10+ Year Member



Hi all.

I am trying to incorporate the following php content

[mydomain.co.uk...]

..into another .php page (let's call it intro.php) using the include function.

Code within intro.php:

<?php include("gallery/index.php?type=sets&setId=72157623233667723"); ?>

(note, .php is in top directory)

However, I get the following error message:

Warning: include(gallery/index.php?type=sets&setId=72157623233667723) [function.include]: failed to open stream: No such file or directory in

now, the bizarre thing is, if I rename my index.php to index.shtml and replace the code with:

<!--#include virtual="/gallery/index.php?type=sets&setId=72157623233667723" -->

and everything gets included correctly!

This issues has been bugging me for days now (I am a php beginner). Could it have something to do with the SET and setID queries?

PS: when I remove the queries:

<?php include("gallery/index.php); ?>

...I get no error message, but also nothing gets imported into index.php!

Help much appreciated,

Glen

Readie

4:48 am on Feb 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



?type=sets&setId=72157623233667723

is $_GET information - it's not part of the file.

You need to have

include("gallery/index.php");

and then get the type and setId from $_GET again, so say you have intro.php:

<?php
include("/gallery/index.php");
?>


The visitor then needs to go to:

www.example.com/intro.php?type=sets&setId=72157623233667723

to get your desired result.

gchristen

1:01 pm on Feb 6, 2010 (gmt 0)

10+ Year Member



thanks, Readie, so are you saying that there is no way to include the content of gallery/index?type=sets&setId=7215762323366772?

rocknbil

8:29 pm on Feb 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Right, there is no $_GET, $_POST, or $_REQUEST being sent from the browser in an include. The reason it works with SSI is because SSI is a different technology, and was designed to accept query string parameters - or args (argument vectors.)

But I spot an easy fix.

First, do this - should be fine as you have it, but being specific always pays off.

include($_SERVER[DOCUMENT_ROOT]."/gallery/index.php....

With SSI, it references files from domain root,

<!--#include virtual="/gallery/index.php...

But as you probably know, doing that in PHP would try to call from /var/www/vhosts . . . etc. with just a leading slash.

Here's an easy fix, just set your GET so when it's included it should fly.

<?php
if (! isset($_GET['type'])) { $_GET['type'] = 'sets'; }
if (! isset($_GET['setId'])) { $_GET['setId'] = '72157623233667723'; }
include($_SERVER[DOCUMENT_ROOT]."gallery/index.php"); ?>

The get values should now be available to index.php.

If those get values are set/used/needed anywhere after this include and this hoses that up, unset them after including:

<?php
if (! isset($_GET['type'])) { $_GET['type'] = 'sets'; }
if (! isset($_GET['setId'])) { $_GET['setId'] = '72157623233667723'; }
include($_SERVER[DOCUMENT_ROOT]."gallery/index.php");
unset($_GET['type']);
unset($_GET['setId']);
?>