Why do does this give me an error?

This is a discussion on Why do does this give me an error? within the PHP Language forums, part of the PHP Programming Forums category; I have a file called t.php: <html> <body> <?php require "http://localhost/~derek/...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-04-2005
Derek Fountain
 
Posts: n/a
Default Why do does this give me an error?

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.
Reply With Quote
  #2 (permalink)  
Old 01-04-2005
Markku Uttula
 
Posts: n/a
Default Re: Why do does this give me an error?

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

Reply With Quote
  #3 (permalink)  
Old 01-04-2005
Matthias Czapla
 
Posts: n/a
Default Re: Why do does this give me an error?

On 2005-01-04, Derek Fountain <nospam@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
Reply With Quote
  #4 (permalink)  
Old 01-04-2005
Derek Fountain
 
Posts: n/a
Default Re: Why do does this give me an error?

> 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?
Reply With Quote
  #5 (permalink)  
Old 01-04-2005
Matthias Czapla
 
Posts: n/a
Default Re: Why do does this give me an error?

On 2005-01-04, Derek Fountain <nospam@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
Reply With Quote
  #6 (permalink)  
Old 01-06-2005
CJ Llewellyn
 
Posts: n/a
Default Re: Why do does this give me an error?

"Derek Fountain" <nospam@example.com> wrote in message
news:41da9304$0$31836$5a62ac22@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



Reply With Quote
  #7 (permalink)  
Old 01-08-2005
JV
 
Posts: n/a
Default Re: Why do does this give me an error?

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
Reply With Quote
  #8 (permalink)  
Old 01-09-2005
George
 
Posts: n/a
Default Re: Why do does this give me an error?

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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:44 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0