By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

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

P: n/a
One
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!

Sep 29 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
On 29 Sep 2006 11:41:09 -0700, "One" <da**********@gmail.comwrote:
>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 :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Sep 29 '06 #2

P: n/a
One

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.
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.

Sep 29 '06 #3

P: n/a
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.

Sep 30 '06 #4

P: n/a
Colin McKinnon wrote:
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') ...

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.
js*******@attglobal.net
==================
Sep 30 '06 #5

P: n/a
One

Jerry Stuckle wrote:
Colin McKinnon wrote:
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!

Oct 1 '06 #6

P: n/a
One wrote:
Jerry Stuckle wrote:
>>Colin McKinnon wrote:
>>>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.
js*******@attglobal.net
==================
Oct 1 '06 #7

P: n/a
One wrote:
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

Oct 1 '06 #8

P: n/a
One

Colin Fine wrote:
One wrote:
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.

Oct 3 '06 #9

P: n/a
Colin Fine wrote:
....
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
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
Oct 3 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.