FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » use GET in include
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: use GET in include [message #174530 is a reply to message #174505] Thu, 16 June 2011 04:58 Go to previous messageGo to previous message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma:
Member
On Jun 15, 1:04 am, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spamyourself.com> wrote:
> On 6/15/2011 6:09 AM, cerr wrote:
>
>> Hi  There, I would like to pass variables with GET to a file i include
>> in my source file but it doesn't work, I get something like
>> "Warning: include(./getfile.php?dir=headers11) [function.include]:
>> failed to open stream: No such file or directory in /mnt/stor5-wc2-
>> dfw1/479383/493261/www.quaaoutlodge.com/web/content/themes/Quaaout11-
>> dev/photoshuffler.js.php on line 29"
>> But when I remove the "?dir=" part from the url it works just fine.
>> What would that be?
>> Line 29 looks like:
>> blablabla<?php include "./getfile.php?dir=".$_GET['dir'];?>
>
>> Thank you for hints&  suggestions!
>
>> Ron
>
> Hi Ron,
>
> You are confusing a http request with an include.
> They are different beasts.
> A http request look like:http://www.example.com/yourphpfile.php
> and you can add info to an URL by adding name/value pairs, like this:http://www.example.com/yourphpfile.php?name=ron&favcol=blue
>
> In $_GET you will find 2 keys:
> $_GET["name"] will contain ron
> $_GET["favcol"] will contain blue
>
> Now to the include:
> If you include a file, you include a file. :-)
> No http or apache involved. So no GET superglobal is set. (And that is
> the reason things don't work as you expected.)
>
> Unless you use http-wrappers, like
> include ("http://www.example.com/getfile.php?file=...");
>
> WARNING: the above is REALLY poor programming to get information into
> your include file: you make a trip using  the http-protocol/apache/new
> PHP instance/etc to get the info into your included file).
>
> How to solve this?
> Depending on your situation, in general:
> 1) Make the included file contain a function or an class, and use that
> function or class from your main file.
> Something like (for Object):
> require_once("class_myFileFetcher.php");
> $myFileFetcher = new FileFetcher();
> $myFileFetcher->setFile(..);
> $myFileFetcher->setHearder(..);
> $myFileFetcher->stream(..);
>
> The above is just fantasycode of course.
>
> Or with a function:
> require_once ("myfunctions/myFileFetcherFunction.php");
> fetchFileAndStream("/some/path/some/file");
>
> option 2 (ugly in my opinion):
> Simply set a variable, then the include. Let the code in the include use
> that variable.
> So:
> $theUglyWayFileName = "/some/path/some/file";
> require_once ("myFileFetcher.php");
> And let the code in myFileFetcher.php use the variable named:
> $theUglyWayFileName.
>

I implemented option 2 so far and it works well - why would thast be
bad anyways?
Thanks! :)

Ron
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: An overloading question
Next Topic: ldap_modify
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 10:16:52 GMT 2024

Total time taken to generate the page: 0.04097 seconds