inactive Posted January 16, 2008 Share Posted January 16, 2008 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. Quote Link to comment Share on other sites More sharing options...
KrisNz Posted January 16, 2008 Share Posted January 16, 2008 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. Quote Link to comment Share on other sites More sharing options...
inactive Posted January 16, 2008 Author Share Posted January 16, 2008 lol i figured i had NFI, but from what you've explained, thats fine and would still work great. only it doesnt work... ??? Quote Link to comment Share on other sites More sharing options...
inactive Posted January 16, 2008 Author Share Posted January 16, 2008 i tried changing my include_path to htdocs within the apache install dir obviously), but same errors, just with obviously the changed include_path listed. any ideas guys? Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted January 16, 2008 Share Posted January 16, 2008 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. Quote Link to comment Share on other sites More sharing options...
inactive Posted January 16, 2008 Author Share Posted January 16, 2008 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. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted January 16, 2008 Share Posted January 16, 2008 The best way is like: monkey.php <?php if ($trace == 'blah') { echo "whatever"; } else { echo "something"; } ?> index.php <?php $trace = "blah"; include("monkey.php"); ?> It will work. Quote Link to comment Share on other sites More sharing options...
inactive Posted January 16, 2008 Author Share Posted January 16, 2008 ha wicked. legendary thanks mmarif4u. Quote Link to comment Share on other sites More sharing options...
inactive Posted October 29, 2014 Author Share Posted October 29, 2014 (edited) You can also set $_GET['trace'] = 'blah'; But it's not a great idea. Edited October 29, 2014 by cainmi 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.