Jump to content

[SOLVED] include error...


inactive

Recommended Posts

hmmm ok well i've seen a few similar threads to this around, but none of them have been closed, so i thought the best idea was to start from scratch.

 

ok well i have two files, index.php and monkey.php. both are in the same directory (which happens to be htdocs, as im running apache).

 

in index.php we have:

<?php

include('monkey.php?trace=blah');

?> 

 

 

 

and in monkey, we effectively have:

<?php

if(isset($_GET['trace'])) { 

$trace = $_GET['trace'];

echo 'some stuff';
echo $trace;
echo 'perhaps some more stuff';

}

?>

 

monkley.php is slightly more cmplicated than that, but i think all that stuff is unnecesary.

 

basically, what i'm trying to do is parse monkey.php?trace=blah as though all that php code was actually within index.php.

 

now i'm reli new to this, so maybe include is even the wrong thing to use, i dunno (i'm hoping someone here might be able to help).

 

instead, this is what is showing up in my apache error logs:

 

[Wed Jan 16 16:40:41 2008] [error] [client 127.0.0.1] PHP Warning:  include(monkey.php?trace=blah) [<a href='function.include'>function.include</a>]: failed to open stream: No error in C:\\server\\Appache\\htdocs\\index.php on line 3
[Wed Jan 16 16:40:41 2008] [error] [client 127.0.0.1] PHP Warning:  include() [<a href='function.include'>function.include</a>]: Failed opening 'monkey.php?trace=blah' for inclusion (include_path='.;C:\\php5\\pear') in C:\\server\\Appache\\htdocs\\index.php on line 3

 

any ideas? i've even tried placing ./ or ../ before monkey.php?trace=blah, but nothing.

 

any help appreciated muchly guys.

 

~mc.

Link to comment
Share on other sites

I'm not quite sure how to explain this thoroughly but suffice it to say that's not how include works. When you include monkey.php in index.php, monkey.php will have access to the all the variables,functions etc that exist in index.php. You don't need to "pass" it anything.

Link to comment
Share on other sites

One thing i am confused about your code:is u pass trace to monkey.php and want to show it in index.php

by using include.

I dont think its a relevant way to do it.

U have to redirect the index page to monkey page then u can get the trace variable value.

U cant include it in the index.php page to get trace.

By including monkey page will not work,because the trace is not in index.php page.include will just include the data in index.php,will not gave you the trace value.

 

Hope it will give some help.

Link to comment
Share on other sites

thanks mmarif4u, you are quite correct. when i removed the get vars (i.e. dropped the question mark and all that followed), the include worked perfectly.

 

so i cant use ? in the file name...but is thers another way to perhaps pass some vars through to monkey.php? again, i'm not sure if i have the right idea here, or even if this is possible.

 

the reason i was using monkey.php?trace=blah is because perhaps in another script i might try to include monkey.php?trace=foobar and i would like it to behave differently.

 

i.e. in monkey.php:

 

$trace = $_GET['trace'];
if (trace == 'blah') { do whatever }
elseif (trace == 'foobar') { do something else }

 

so i need some way to pass a variable or sorts to monkey.php as i include it, so it will behave differently. is this possible?

 

from what Kris said, maybe before i write the include i just set $trace then,

i.e. in index.php

$trace = 'blah';
include('monkey.php');

 

and then in some other file

 

$trace = 'foobar';
include('monkey.php');

 

is this a better idea?

 

thanks everyone for your help.

 

 

Link to comment
Share on other sites

  • 6 years later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.