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/...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
> 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? |
|
|||
|
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 |
|
|||
|
"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 |
|
|||
|
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 |
|
|||
|
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 |