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

Why do does this give me an error?

P: n/a
I have a file called t.php:

<html>
<body>

<?php
require "http://localhost/~derek/l.php";
rp(3);
?>

</body>
</html>
and l.php:

<?php
echo "define function...";
function rp( $num )
{
echo "rp: $num";
}
echo "defined";
?>
When I load t.php into my browser it prints "define function...defined
Fatal error: Call to undefined function: rp()
in /home/derek/public_html/t.php on line 6"

So, I know the library code is being loaded and executed (because the
strings are echoed) but rp() isn't being defined. Experimentation shows
it's not just functions which I'm not getting defined, as I get the same
sort of error if I just define a variable and try to get it printed in
t.php.

Can someone tell me what I'm doing wrong? I'm using PHP-4.3.4 on SUSE
LINUX-9.1.
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Derek Fountain wrote:
So, I know the library code is being loaded and executed (because
the
strings are echoed) but rp() isn't being defined.


Actually, Your webserver is executing the php-file (and thus outputs
the lines) but you're receiveing only the executed outcome, not the
php-file itself.

So essentially, what you get from http://localhost/~derek/l.php is the
following:

define function...defined

and not what you're expecting. Hope I'm making sense here :)

--
Markku Uttula

Jul 17 '05 #2

P: n/a
On 2005-01-04, Derek Fountain <no****@example.com> wrote:
I have a file called t.php:

<html>
<body>

<?php
require "http://localhost/~derek/l.php";
rp(3);
?>

</body>
</html>
and l.php:

<?php
echo "define function...";
function rp( $num )
{
echo "rp: $num";
}
echo "defined";
?>
When I load t.php into my browser it prints "define function...defined
Fatal error: Call to undefined function: rp()
in /home/derek/public_html/t.php on line 6"

So, I know the library code is being loaded and executed (because the
strings are echoed) but rp() isn't being defined. Experimentation shows
it's not just functions which I'm not getting defined, as I get the same
sort of error if I just define a variable and try to get it printed in
t.php.


You are not including the source code of l.php but the result of it being
run on the server, which is just the string "define function...defined",
which in turn is interpreted as HTML and displayed by t.php. You must either
include the file locally (e.g. require "/home/derek/l.php";) or make the
server not interpret the file (e.g. by giving it another extension like
".inc" or ".txt").

Regards
Matthias
Jul 17 '05 #3

P: n/a
> You are not including the source code of l.php but the result of it being
run on the server, which is just the string "define function...defined",
which in turn is interpreted as HTML and displayed by t.php. You must
either include the file locally (e.g. require "/home/derek/l.php";) or
make the server not interpret the file (e.g. by giving it another
extension like ".inc" or ".txt").


Ah, right. Thanks. But just to clarify, if I rename it to something other
than .php, and someone learns the pathname to the file, they can ask my
webserver for the file directly and they'll get to see my source code -
right?
Jul 17 '05 #4

P: n/a
On 2005-01-04, Derek Fountain <no****@example.com> wrote:
You are not including the source code of l.php but the result of it being
run on the server, which is just the string "define function...defined",
which in turn is interpreted as HTML and displayed by t.php. You must
either include the file locally (e.g. require "/home/derek/l.php";) or
make the server not interpret the file (e.g. by giving it another
extension like ".inc" or ".txt").


Ah, right. Thanks. But just to clarify, if I rename it to something other
than .php, and someone learns the pathname to the file, they can ask my
webserver for the file directly and they'll get to see my source code -
right?


Correct.

Regards
Matthias
Jul 17 '05 #5

P: n/a
"Derek Fountain" <no****@example.com> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
You are not including the source code of l.php but the result of it being run on the server, which is just the string "define function...defined",
which in turn is interpreted as HTML and displayed by t.php. You must
either include the file locally (e.g. require "/home/derek/l.php";) or
make the server not interpret the file (e.g. by giving it another
extension like ".inc" or ".txt").


Ah, right. Thanks. But just to clarify, if I rename it to something other
than .php, and someone learns the pathname to the file, they can ask my
webserver for the file directly and they'll get to see my source code -
right?


Yes, for which very reason you'll probably want to want to use a more
appropriate technology such as SOAP

http://www.php.net/manual/en/ref.soap.php

Jul 17 '05 #6

P: n/a
JV
Derek Fountain wrote:
Ah, right. Thanks. But just to clarify, if I rename it to something other
than .php, and someone learns the pathname to the file, they can ask my
webserver for the file directly and they'll get to see my source code -
right?


yup but if you place the files that you are wanting to display in this
manner in a folder that is outside of the web-root server such as

/var/www/txt/foo.bar

instead of in

/var/www/html/foo.bar

where /var/www/html/ is the web-root directory

then the files in the txt/ folder are not accessible directly to
browsers and php files can load them by using ../txt/foo.bar

this is a fairly basic principle of site design/management i think... :/

hth
JV
Jul 17 '05 #7

P: n/a
Hey,

While JV is right, that would only work if the files you include reside
on the same server as your script (assuming your script would have
access to the files).

Otherwise, as I imagine you want, to execute remotely hosted functions
and in the same time conseal the source, CJ Llewellyn is right that you
should either use a technology like SOAP or just design a simple
interface to your PHP functions (latter being, to my preference, the
worse approach, because you can just use something standartized).
George

Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.