473,411 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

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.
Jul 17 '05 #1
7 1483
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
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
> 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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Fendi Baba | last post by:
The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. .............................................................. var...
0
by: Dirk Försterling | last post by:
Hi all, a few days ago, I upgraded from PostgreSQL 7.2.1 to 7.4, following the instructions in the INSTALL file, including dump and restore. All this worked fine without any error (message). ...
10
by: DataBard007 | last post by:
Hello Access Gurus: I use Win98SE and Access97. I just built a simple Access97 application which holds all contact information for my personal contacts, such as first name, last name, address,...
29
by: SysSpider | last post by:
Hi again, This is my problem: when i try to compile the code that contains the function below, i get this: -- gcc:21: error: case label does not reduce to an integer constant gcc:24: error:...
5
by: Genboy | last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1, is no longer compiling for me via the command line. As I have done 600 times in the last year and a half, I can compile to...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
25
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does parseInt('09') give an error? ----------------------------------------------------------------------- ...
19
by: Angus | last post by:
I have a socket class CTestClientSocket which I am using to simulate load testing. I create multiple instances of the client like this: for (int i = 0; i < 5; i++) { CTestClientSocket* pTemp...
3
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does simple decimal arithmetic give strange results?...
32
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.