Connecting Tech Pros Worldwide Help | Site Map

Error - Cannot pass paramter --> Failed to open stream

One
Guest
 
Posts: n/a
#1: Sep 29 '06
I have a main.php file that calls a php navigation menu.

I want to pass the menu file a parameter to tell it which menu to
display.

Inside the main.php I have :
include "/home/ottadca1/public_html/includes/leftnav.php?menuid=dave";

But the error is :
Warning:
main(/home/ottadca1/public_html/includes/leftnav.php?menuid=dave)
[function.main]: failed to open stream: No such file or directory in
/home/ottadca1/public_html/1menu.php on line 117

Warning: main() [function.include]: Failed opening
'/home/ottadca1/public_html/includes/leftnav.php?menuid=dave' for
inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in
/home/ottadca1/public_html/1menu.php on line 117

However - if use the exact same line without passing a parameter it
works fine.
This works : include "/home/ottadca1/public_html/includes/leftnav.php";

I don't understand. I've used this technique in the past.
Is there some sort of php configuration I am missing ???

THANKS!

Andy Hassall
Guest
 
Posts: n/a
#2: Sep 29 '06

re: Error - Cannot pass paramter --> Failed to open stream


On 29 Sep 2006 11:41:09 -0700, "One" <david.hunter@gmail.comwrote:
Quote:
>I have a main.php file that calls a php navigation menu.
>
>I want to pass the menu file a parameter to tell it which menu to
>display.
>
>Inside the main.php I have :
include "/home/ottadca1/public_html/includes/leftnav.php?menuid=dave";
You can't do that. "?" is for URLs, but you're specifying a filename. With the
"?", you're specifying a filename that doesn't exist.

If you want to pass variables into the include file, just set them before you
do the include, they'll be visible in the include file. (Or pass them as
parameters to whatever functions you define in the include file).

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
One
Guest
 
Posts: n/a
#3: Sep 29 '06

re: Error - Cannot pass paramter --> Failed to open stream



Andy Hassall wrote:
Quote:
You can't do that. "?" is for URLs, but you're specifying a filename. With the
"?", you're specifying a filename that doesn't exist.
ah ha. I know - In the past I have passed it as a parameter like this :
include "http://www.www.com/file.php?menu=david"
This has worked.
Quote:
If you want to pass variables into the include file, just set them before you
do the include, they'll be visible in the include file. (Or pass them as
parameters to whatever functions you define in the include file).
You mean like this ?

<?php
echo "<form><input type="hidden" name=menuid" value="david"></form>";
include file.php
?>

I thought I did this - and it did not work.
In the php include I used :
$menuid = $_GET['menuid']

Thanks for replying.

Colin McKinnon
Guest
 
Posts: n/a
#4: Sep 30 '06

re: Error - Cannot pass paramter --> Failed to open stream


One wrote:
Quote:
Andy Hassall wrote:
Quote:
> You can't do that. "?" is for URLs, but you're specifying a filename.
> With the
>"?", you're specifying a filename that doesn't exist.
>
ah ha. I know - In the past I have passed it as a parameter like this :
include "http://www.www.com/file.php?menu=david"
This has worked.
Yes, but its very dangerous unless you really, really know what you're
doing.
Quote:
>
Quote:
> If you want to pass variables into the include file, just set them
> before you
>do the include, they'll be visible in the include file. (Or pass them as
>parameters to whatever functions you define in the include file).
>
You mean like this ?
>
<?php
echo "<form><input type="hidden" name=menuid" value="david"></form>";
include file.php
?>
>
No - like

$GLOBALS['menuid']='david';
include ('file.php');

C.

Jerry Stuckle
Guest
 
Posts: n/a
#5: Sep 30 '06

re: Error - Cannot pass paramter --> Failed to open stream


Colin McKinnon wrote:
Quote:
One wrote:
>
>
Quote:
>>Andy Hassall wrote:
>>
Quote:
>>You can't do that. "?" is for URLs, but you're specifying a filename.
>>With the
>>>"?", you're specifying a filename that doesn't exist.
>>
>>ah ha. I know - In the past I have passed it as a parameter like this :
>>include "http://www.www.com/file.php?menu=david"
>>This has worked.
>
>
Yes, but its very dangerous unless you really, really know what you're
doing.
>
Quote:
Quote:
>>If you want to pass variables into the include file, just set them
>>before you
>>>do the include, they'll be visible in the include file. (Or pass them as
>>>parameters to whatever functions you define in the include file).
>>
>>You mean like this ?
>>
>><?php
>>echo "<form><input type="hidden" name=menuid" value="david"></form>";
>>include file.php
>>?>
>>
>
No - like
>
$GLOBALS['menuid']='david';
include ('file.php');
>
C.
>
You don't even need to use globals.

Just

$menuid = 'david';

and in the include file you can use

if ($menuid == 'david') ...

An include acts just like if you cut/paste the code from the included
file in place of the 'include' statement.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
One
Guest
 
Posts: n/a
#6: Oct 1 '06

re: Error - Cannot pass paramter --> Failed to open stream



Jerry Stuckle wrote:
Quote:
Colin McKinnon wrote:
Quote:
One wrote:

Quote:
>Andy Hassall wrote:
>
>You can't do that. "?" is for URLs, but you're specifying a filename.
>With the
>>"?", you're specifying a filename that doesn't exist.
>
>ah ha. I know - In the past I have passed it as a parameter like this :
>include "http://www.www.com/file.php?menu=david"
>This has worked.

Yes, but its very dangerous unless you really, really know what you're
doing.
Quote:
>If you want to pass variables into the include file, just set them
>before you
>>do the include, they'll be visible in the include file. (Or pass them as
>>parameters to whatever functions you define in the include file).
>
>You mean like this ?
>
><?php
>echo "<form><input type="hidden" name=menuid" value="david"></form>";
>include file.php
>?>
>
No - like

$GLOBALS['menuid']='david';
include ('file.php');

C.
>
You don't even need to use globals.
>
Just
>
$menuid = 'david';
>
and in the include file you can use
>
if ($menuid == 'david') ...
>
Yeah!!

Big thanks to Jerry and Colin. I have successfully impltmented your
solution.

BTW - what is the risk passing the variable to the file via and httP
request ?
The include file has nothing to execute.

thanks again!

Jerry Stuckle
Guest
 
Posts: n/a
#7: Oct 1 '06

re: Error - Cannot pass paramter --> Failed to open stream


One wrote:
Quote:
Jerry Stuckle wrote:
>
Quote:
>>Colin McKinnon wrote:
>>
Quote:
>>>One wrote:
>>>
>>>
>>>
>>>>Andy Hassall wrote:
>>>>
>>>>
>>>>>You can't do that. "?" is for URLs, but you're specifying a filename.
>>>>>With the
>>>>>"?", you're specifying a filename that doesn't exist.
>>>>
>>>>ah ha. I know - In the past I have passed it as a parameter like this :
>>>>include "http://www.www.com/file.php?menu=david"
>>>>This has worked.
>>>
>>>
>>>Yes, but its very dangerous unless you really, really know what you're
>>>doing.
>>>
>>>
>>>>>If you want to pass variables into the include file, just set them
>>>>>before you
>>>>>do the include, they'll be visible in the include file. (Or pass them as
>>>>>parameters to whatever functions you define in the include file).
>>>>
>>>>You mean like this ?
>>>>
>>>><?php
>>>>echo "<form><input type="hidden" name=menuid" value="david"></form>";
>>>>include file.php
>>>>?>
>>>>
>>>No - like
>>>
>>>$GLOBALS['menuid']='david';
>>>include ('file.php');
>>>
>>>C.
>>>
>>
>>You don't even need to use globals.
>>
>>Just
>>
> $menuid = 'david';
>>
>>and in the include file you can use
>>
> if ($menuid == 'david') ...
>>
>
>
Yeah!!
>
Big thanks to Jerry and Colin. I have successfully impltmented your
solution.
>
BTW - what is the risk passing the variable to the file via and httP
request ?
The include file has nothing to execute.
>
thanks again!
>
Well, it can easily be changed by the user - being a parameter to the
URL. And if you use:

include ('http://...);

You're making another call to the server, getting it to access and parse
the page and return the results to your current page. If it's a remote
system, you'll probably have to do that. But it's a waste to be doing
it to your local system. Just including the file with:

include ('/path/to/file...');

is much more efficient. Additionally, you get the unparsed page (i.e.
PHP code) which can be executed here, instead of the html output by the
server in the previous include.

And btw - when you do use the first include, you have to make sure you
remove out all of the extra tags, such as DOCTYPE, <head>, </body>, etc.
from the included file output to ensure you are sending valid html to
the client.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Colin Fine
Guest
 
Posts: n/a
#8: Oct 1 '06

re: Error - Cannot pass paramter --> Failed to open stream


One wrote:
Quote:
I have a main.php file that calls a php navigation menu.
>
I want to pass the menu file a parameter to tell it which menu to
display.
>
Inside the main.php I have :
include "/home/ottadca1/public_html/includes/leftnav.php?menuid=dave";
>
But the error is :
Warning:
main(/home/ottadca1/public_html/includes/leftnav.php?menuid=dave)
[function.main]: failed to open stream: No such file or directory in
/home/ottadca1/public_html/1menu.php on line 117
>
Warning: main() [function.include]: Failed opening
'/home/ottadca1/public_html/includes/leftnav.php?menuid=dave' for
inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in
/home/ottadca1/public_html/1menu.php on line 117
>
However - if use the exact same line without passing a parameter it
works fine.
This works : include "/home/ottadca1/public_html/includes/leftnav.php";
>
I don't understand. I've used this technique in the past.
Is there some sort of php configuration I am missing ???
>
THANKS!
>
You seem to be confusing HTTP (or rather CGI) and PHP.

The '?arg=value&arg=value' syntax is part of CGI, and is interpreted by
CGI programs running typically on web browsers. While many CGI
programs are written in PHP, the syntax has nothing to do with PHP: the
program that interprets it might be in Perl, VB, Asp, or other languages.

When you use
include('filename');

you are staying within PHP, telling it to read its some code from
somewhere else.

If you use
include("http://url");

you are telling your PHP programme to send an HTTP request to that
server, and parse the result as PHP code. The server will send back just
what you would get if specified that URL to your browser - which will
not usually be PHP source.

Colin

One
Guest
 
Posts: n/a
#9: Oct 3 '06

re: Error - Cannot pass paramter --> Failed to open stream



Colin Fine wrote:
Quote:
One wrote:
Quote:
I have a main.php file that calls a php navigation menu.

I want to pass the menu file a parameter to tell it which menu to
display.

Inside the main.php I have :
include "/home/ottadca1/public_html/includes/leftnav.php?menuid=dave";

But the error is :
Warning:
main(/home/ottadca1/public_html/includes/leftnav.php?menuid=dave)
[function.main]: failed to open stream: No such file or directory in
/home/ottadca1/public_html/1menu.php on line 117

Warning: main() [function.include]: Failed opening
'/home/ottadca1/public_html/includes/leftnav.php?menuid=dave' for
inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in
/home/ottadca1/public_html/1menu.php on line 117

However - if use the exact same line without passing a parameter it
works fine.
This works : include "/home/ottadca1/public_html/includes/leftnav.php";

I don't understand. I've used this technique in the past.
Is there some sort of php configuration I am missing ???

THANKS!
>
You seem to be confusing HTTP (or rather CGI) and PHP.
>
The '?arg=value&arg=value' syntax is part of CGI, and is interpreted by
CGI programs running typically on web browsers. While many CGI
programs are written in PHP, the syntax has nothing to do with PHP: the
program that interprets it might be in Perl, VB, Asp, or other languages.
>
When you use
include('filename');
>
you are staying within PHP, telling it to read its some code from
somewhere else.
>
If you use
include("http://url");
>
you are telling your PHP programme to send an HTTP request to that
server, and parse the result as PHP code. The server will send back just
what you would get if specified that URL to your browser - which will
not usually be PHP source.
>
Colin
Big thanks to Colin and Jerry for such concise answers.

Thanks again - everything is working well and as expected.

Colin Fine
Guest
 
Posts: n/a
#10: Oct 3 '06

re: Error - Cannot pass paramter --> Failed to open stream


Colin Fine wrote:
....
Quote:
You seem to be confusing HTTP (or rather CGI) and PHP.
>
The '?arg=value&arg=value' syntax is part of CGI, and is interpreted by
CGI programs running typically on web browsers. While many CGI
^^^^^^^^ servers, of course
Quote:
programs are written in PHP, the syntax has nothing to do with PHP: the
program that interprets it might be in Perl, VB, Asp, or other languages.
Colin
Closed Thread