I would like to make use of two separate PHP applications which happen
to share some class names; trying to include both from one script
results in the expected error, "cannot redefine class foo." or somesuch.
Using a fully qualified URL instead of the local file path in the
include() would work, except that the applications then do not have
access to the users cookies -- the requests are coming from the server
itself, not the user.
The virtual() function seems to be in flux -- there seems to be
disagreement as to whether it is supposed to work with .php files;
besides it doesn't work on the two servers I have.
So, is there a way to include a .php file such that it is evaluated
outside of the context of the php script from which it is included, in
its own namespace, but so that the request for the file still comes from
the user's browser itself?
I don't want to use frames for UI reasons. Thanks for any advice,
Nathan 7 5306
Nathan Lamont wrote: I would like to make use of two separate PHP applications which happen to share some class names; trying to include both from one script results in the expected error, "cannot redefine class foo." or somesuch.
Just use
include_once('classfile.php');
or
require_once('classfile.php');
(it's better to use require() if you *always* want the file to be "included"
- you may improve speed a little by using include() for code that is
conditionally included or where you specify the filename:
e.g.
include('includefiles/'.$myclassname.'.php');
So, is there a way to include a .php file such that it is evaluated outside of the context of the php script from which it is included, in its own namespace, but so that the request for the file still comes from the user's browser itself?
You can do things like
include('http://example.com/dynamic.php');
but the request will come from the webserver, not from the user's browser.
I don't quite understand what you're trying to do here - if you could explain
better (use words, don't post your code!) it might be easy for people to help
you
Matt
In article <a_*****************@wards.force9.net>,
matty <ma*******@askmenoquestions.co.uk> wrote:
[snip] You can do things like include('http://example.com/dynamic.php'); but the request will come from the webserver, not from the user's browser.
I don't quite understand what you're trying to do here - if you could explain better (use words, don't post your code!) it might be easy for people to help you
Matt
Thanks for responding. Let me illustrate:
Suppose I have two php scripts, foo.php and bar.php, each of which
happens to use its own separate definition of a class, say myClass. In
foo.php, myClass does one thing and in bar.php it does something
entirely different. Both foo.php and bar.php rely on data stored in the
end-user's cookies.
If I want to make use of the output of both foo.php and bar.php in a
target script, say main.php, I can't simply include() a local path to
both foo.php and bar.php, because their class names collide.
If, in main.php, I use a full url in the include() statement, foo.php
and bar.php can't perform their full functions, which rely on cookies,
since as we both pointed out the request will actually be coming from
the computer serving up main.php.
In reality, foo.php and bar.php are large multi-file php applications
that may need to be independently updated; modifying them is not an
option.
I don't want to use frames for UI reasons. So, my question is again, is
there a way to include a .php file such that it is evaluated
outside of the context of the php script from which it is included, in
its own namespace, but so that the request for the file still comes from
the user's browser itself?
I haven't been able to find a way to do so; is there another solution to
my problem?
Thanks,
Nathan
Nathan Lamont wrote: In article <a_*****************@wards.force9.net>, matty <ma*******@askmenoquestions.co.uk> wrote:
[snip]
You can do things like include('http://example.com/dynamic.php'); but the request will come from the webserver, not from the user's browser.
I don't quite understand what you're trying to do here - if you could explain better (use words, don't post your code!) it might be easy for people to help you
Matt
Thanks for responding. Let me illustrate:
Suppose I have two php scripts, foo.php and bar.php, each of which happens to use its own separate definition of a class, say myClass. In foo.php, myClass does one thing and in bar.php it does something entirely different. Both foo.php and bar.php rely on data stored in the end-user's cookies.
If I want to make use of the output of both foo.php and bar.php in a target script, say main.php, I can't simply include() a local path to both foo.php and bar.php, because their class names collide.
If, in main.php, I use a full url in the include() statement, foo.php and bar.php can't perform their full functions, which rely on cookies, since as we both pointed out the request will actually be coming from the computer serving up main.php.
In reality, foo.php and bar.php are large multi-file php applications that may need to be independently updated; modifying them is not an option.
I don't want to use frames for UI reasons. So, my question is again, is there a way to include a .php file such that it is evaluated outside of the context of the php script from which it is included, in its own namespace, but so that the request for the file still comes from the user's browser itself?
I haven't been able to find a way to do so; is there another solution to my problem?
OK, you could use cURL, or something like Pear's HTTP::Request
( http://pear.php.net/) to fetch the output of the scripts as a http request,
BUT here's the important bit:
when you fetch the page, do it as an HTTP proxy, so pass any and all http
headers along (like user-agent, http-referer, etc) and send remote-addr
and x-forwarded-for headers to match the user's ip address
That way, the webserver at the other end thinks you're a proxy server, and then
everything works ok.
If you just want to include the files locally, you'll have to change the class
names - that's how it works. It may not be too bad, if you're just redfining the
main boundary class, but it could well be a big task!
hth
Nathan Lamont: Suppose I have two php scripts, foo.php and bar.php, each of which happens to use its own separate definition of a class, say myClass. In foo.php, myClass does one thing and in bar.php it does something entirely different. Both foo.php and bar.php rely on data stored in the end-user's cookies.
If I want to make use of the output of both foo.php and bar.php in a target script, say main.php, I can't simply include() a local path to both foo.php and bar.php, because their class names collide.
If, in main.php, I use a full url in the include() statement, foo.php and bar.php can't perform their full functions, which rely on cookies, since as we both pointed out the request will actually be coming from the computer serving up main.php.
In reality, foo.php and bar.php are large multi-file php applications that may need to be independently updated; modifying them is not an option.
I don't want to use frames for UI reasons. So, my question is again, is there a way to include a .php file such that it is evaluated outside of the context of the php script from which it is included, in its own namespace, but so that the request for the file still comes from the user's browser itself?
I haven't been able to find a way to do so; is there another solution to my problem?
In short no, because PHP doesn't have namespaces. To me it sounds like you
need to choose one of the classes and execute it's code by making a
separate http request, forwarding the cookie data to this request, and then
include the result. Maybe curl can help: http://www.php.net/curl
André Nęss
In article <Dp*****************@wards.force9.net>,
matty <ma*******@askmenoquestions.co.uk> wrote: OK, you could use cURL, or something like Pear's HTTP::Request (http://pear.php.net/) to fetch the output of the scripts as a http request, BUT here's the important bit:
when you fetch the page, do it as an HTTP proxy, so pass any and all http headers along (like user-agent, http-referer, etc) and send remote-addr and x-forwarded-for headers to match the user's ip address
That way, the webserver at the other end thinks you're a proxy server, and then everything works ok.
If you just want to include the files locally, you'll have to change the class names - that's how it works. It may not be too bad, if you're just redfining the main boundary class, but it could well be a big task!
OK -- thanks for the pointers, I appreciate it (thanks to Andre Naess
too). Your curl approach looks good and I wouldn't have thought of it.
Thanks again,
Nathan Suppose I have two php scripts, foo.php and bar.php, each of which happens to use its own separate definition of a class, say myClass. In foo.php, myClass does one thing and in bar.php it does something entirely different. Both foo.php and bar.php rely on data stored in the end-user's cookies.
If I want to make use of the output of both foo.php and bar.php in a target script, say main.php, I can't simply include() a local path to both foo.php and bar.php, because their class names collide.
If, in main.php, I use a full url in the include() statement, foo.php and bar.php can't perform their full functions, which rely on cookies, since as we both pointed out the request will actually be coming from the computer serving up main.php.
In reality, foo.php and bar.php are large multi-file php applications that may need to be independently updated; modifying them is not an option.
I don't want to use frames for UI reasons. So, my question is again, is there a way to include a .php file such that it is evaluated outside of the context of the php script from which it is included, in its own namespace, but so that the request for the file still comes from the user's browser itself?
I haven't been able to find a way to do so; is there another solution to my problem?
I'm still not clear to me exactly what you're asking for, but I just
wanted to double-check you are aware of the ability to define several
include_paths in order:
php_value include_path /path/to/1st/:/path/to/2nd/
I found this very useful on my server where I have about 30 sites. Many of
them use the same common code framework, in
/path/to/webroot/common/libraries/ but in same cases a more specific
version of a library is required, which is within the site itself, i.e.
/path/to/webroot/sitename/libraries/
hence
include_path
/path/to/webroot/sitename/libraries/:/path/to/webroot/common/libraries/
which means that if there is a local one, that will be used, otherwise it
will fall back to the generic version.
Martin Lucas-Smith www.geog.cam.ac.uk/~mvl22 www.lucas-smith.co.uk
Senior Computing Technician (Web Technician)
Department of Geography, University of Cambridge (01223 3)33390
& Webmaster, SPRI
Scott Polar Research Institute, University of Cambridge
In article
<Pi*************************************@green.csi .cam.ac.uk>,
Martin Lucas-Smith <mv***@cam.ac.uk> wrote: I'm still not clear to me exactly what you're asking for, but I just wanted to double-check you are aware of the ability to define several include_paths in order:
[snip]
I think what you're missing is that I need to include the output of two
distinct classes in two distinct files at the same time, where the
classes have the same name, but different functions. The complication
which prevents the simple solution of using a full url
(inlude('http://www.example.com/foo.php')) is that the distinct files
make use of the user's cookies.
Thanks,
Nathan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Toke H?iland-J?rgensen |
last post by:
Hello. I am quite new to the c++ language, and am still trying to
learn it. I recently discovered how using include files would allow me
to split up my code into smaller segments, instead of having...
|
by: wukexin |
last post by:
Help me, good men. I find mang books that introduce bit "mang header
files",they talk too bit,in fact it is my too fool, I don't learn it, I have
do a test program, but I have no correct doing...
|
by: Steven T. Hatton |
last post by:
I will assume many people reading this would never create anything similar
to the example below. So let me preface this with _*IF*_ you were in a
situation where you had to chose between using...
|
by: puzzlecracker |
last post by:
after reading some of the post I found out something rather radical to
my previous understanding: that when you do
#include<iostream>
#include<string>
#include<vector>
etc
compiler puts...
|
by: Steven T. Hatton |
last post by:
I'm trying to create an baseclass that will serve as a parent for reference
counted objects handled by boost::intrusive_ptr<>. The documentation
didn't provide much in the way of describing what...
|
by: Jon Rea |
last post by:
I am currently cleaning up an application which was origainlly hashed
together with speed of coding in mind and therefore contains quite a few
"hacky" shortcuts.
As part of this "revamping"...
|
by: maxwell |
last post by:
I'm having a problem using the XML "include" mechanism, which I think
has to do with namespaces.
I have an XML file that has a lot of repetition--a sequence of elements
that appear multiple...
|
by: Jack Li |
last post by:
Hi,
If I declare multiple namspaces, each in a separate file, how do I
specify their path with the "using" directives?
Say I have 2 namespaces and 1 main function, all in separate files such
as...
|
by: Hua.watson |
last post by:
I want to add some declaration intio my namespace. But I do not have
the right to modify proto header files.
So I try
namespace mynamespace{
#include "a.h"
#include "b.h"
}
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
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...
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |