473,586 Members | 2,817 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get url of current url from included script on different server

I have a banner script that is included in php on a website but the
actual script is hosted on a different site allowing me to only edit
one file to update the script.

I need to store in a variable the hostname that the included script is
being run on NOT the master url where it is hosted.

Everything I try gives the url of where the script is hosted and NOT
the location of the page where it is being called from which is what I
want as I need be able to tell the banner script not to show the banner
for the site which is it on.

tia

Jan 10 '06 #1
7 3371
Venturer said the following on 10/01/2006 09:52:
I have a banner script that is included in php on a website but the
actual script is hosted on a different site allowing me to only edit
one file to update the script.

I need to store in a variable the hostname that the included script is
being run on NOT the master url where it is hosted.


I'm assuming you're include()-ing the script as something like:

include("http://remote.server.e xample.com/script.php");

Is the remote server set to execute PHP or not?

* If it is, then script.php is being run on the remote server, not the
local server, so you're actually include()-ing the *output* of
script.php, not the PHP code itself. In which case, you will need to
either pass the hostname in the request for script.php, e.g.:

include("http://remote.server.e xample.com/script.php?host =http://local.example.c om/mainscript.php" );
* If the remote server is not set to execute PHP, then script.php will
be executed on the local server, so there should be no problem. However,
this configuration is a potential security risk, as anyone can request
script.php and see the code.
--
Oli
Jan 10 '06 #2
Oli Filth wrote:
Venturer said the following on 10/01/2006 09:52:
I have a banner script that is included in php on a website but the
actual script is hosted on a different site allowing me to only edit
one file to update the script.

I need to store in a variable the hostname that the included script is
being run on NOT the master url where it is hosted.

I'm assuming you're include()-ing the script as something like:

include("http://remote.server.e xample.com/script.php");

Is the remote server set to execute PHP or not?

* If it is, then script.php is being run on the remote server, not the
local server, so you're actually include()-ing the *output* of
script.php, not the PHP code itself. In which case, you will need to
either pass the hostname in the request for script.php, e.g.:

include("http://remote.server.e xample.com/script.php?host =http://local.example.c om/mainscript.php" );


This is something that I have never done (include from another
server/domain)...

Out of curiosity, does the $_GET array actually get populated with
values sent in this way for the remote script? When I want that
behavior, I usually use something like curl to send the request and
receive the output.

I know that if you do something like:
include 'myfile.php?var =val1';

That php looks for a file with that exact name (which will not exist in
most cases). Therefore in order to make that work (locally anyway),
you'd need to set the variable before the file was included.

--
Justin Koivisto, ZCE - ju****@koivi.co m
http://koivi.com
Jan 10 '06 #3
Justin Koivisto said the following on 10/01/2006 14:57:
Oli Filth wrote:
* If it is, then script.php is being run on the remote server, not the
local server, so you're actually include()-ing the *output* of
script.php, not the PHP code itself. In which case, you will need to
either pass the hostname in the request for script.php, e.g.:

include("http ://remote.server.e xample.com/script.php?host =http://local.example.c om/mainscript.php" );
Out of curiosity, does the $_GET array actually get populated with
values sent in this way for the remote script?


Yes. The receiving remote server doesn't care (or know) where the HTTP
request for script.php came from, so it acts exactly as if someone had
requested that URL from their browser.

I know that if you do something like:
include 'myfile.php?var =val1';

That php looks for a file with that exact name (which will not exist in
most cases). Therefore in order to make that work (locally anyway),
you'd need to set the variable before the file was included.


Well yes, because "?var=var1" is meaningless in a local filesystem.
Setting the local variable works because both scripts are being run
locally in the same PHP instance.

If you do something like include("http://example.com/file.php?foo=ba r"),
then PHP goes away and performs an HTTP request, where "?foo=bar" has
meaning, i.e. a GET sub-string.

--
Oli
Jan 10 '06 #4
Oli Filth wrote:
Justin Koivisto said the following on 10/01/2006 14:57:
Oli Filth wrote:
include("http://remote.server.e xample.com/script.php?host =http://local.example.c om/mainscript.php" );


Out of curiosity, does the $_GET array actually get populated with
values sent in this way for the remote script?


Yes. The receiving remote server doesn't care (or know) where the HTTP
request for script.php came from, so it acts exactly as if someone had
requested that URL from their browser.


I'll have to keep that in mind next time I consider using curl for a
simple get request...
I know that if you do something like:
include 'myfile.php?var =val1';

That php looks for a file with that exact name (which will not exist in
most cases). Therefore in order to make that work (locally anyway),
you'd need to set the variable before the file was included.


Well yes, because "?var=var1" is meaningless in a local filesystem.
Setting the local variable works because both scripts are being run
locally in the same PHP instance.


That's what I was trying to explain. When I first started php (many
years ago), I learned that while experimenting with different things.
One of these days I'll get my site together that I plan to use for
articles and such like that. ;)

--
Justin Koivisto, ZCE - ju****@koivi.co m
http://koivi.com
Jan 10 '06 #5
ok i'll explain more...

a script on www.master.com/script.php

contains a list of items:

1.com
2.com
3.com

the script.php file is included in a page:

www.2.com/index.php

as

include("http://www.master.com/script.php");

the script.php checks for the domain it is on (which should tell it its
on www.2.com/index.php) and then makes sure it WONT display its own
domain in the script.php list... eg it will show 1.com and 3.com but
not 2.com

Of course what happens is that the domain test comes back as saying its
on http://www.master.com

How else can I do this and not have to update 50 websites when I want
to make a common change to one file?

Jan 10 '06 #6
Venturer said the following on 10/01/2006 22:01:
ok i'll explain more...

a script on www.master.com/script.php

contains a list of items:

1.com
2.com
3.com

the script.php file is included in a page:

www.2.com/index.php

as

include("http://www.master.com/script.php");

the script.php checks for the domain it is on (which should tell it its
on www.2.com/index.php) and then makes sure it WONT display its own
domain in the script.php list... eg it will show 1.com and 3.com but
not 2.com

Of course what happens is that the domain test comes back as saying its
on http://www.master.com

How else can I do this and not have to update 50 websites when I want
to make a common change to one file?


Well, the easiest way is to pass a GET variable which contains the
"local" URL when include()-ing http://www.master.com/script.php, as I
suggested in response to your original post.

However, we might be able to help more if you explain *why* you want to
access a remote script in this way.
P.S. "www.master.com " is a domain, whereas "http://www.master.com" and
"http://www.master.com/script.php" are URLs.

--
Oli
Jan 10 '06 #7

Venturer wrote:
include("http://www.master.com/script.php");

the script.php checks for the domain it is on (which should tell it its
on www.2.com/index.php) and then makes sure it WONT display its own
domain in the script.php list... eg it will show 1.com and 3.com but
not 2.com

Of course what happens is that the domain test comes back as saying its
on http://www.master.com

How else can I do this and not have to update 50 websites when I want
to make a common change to one file?


Ah, you might be looking for the "Non-Standard File Extension" Try

include 'http://www.remotedomai n.com/script.xyz';
this script should have open/close php tags.

You can use the $_SERVER array in script.xyz as if it were on the
includer domain. I use this all the time to put hit counter code, etc
in my sites.

Do be aware, anyone could browse to www.remotedomain.com/script.xyz and
see the raw php code, so you shouldnt use this for anything secret.

--
juglesh

Jan 11 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4024
by: Sandman | last post by:
Ok, so I have PHP set upp to ato_prepend and auto_append files to every script I run. So if I someone surfs to /index.php, these scripts run: init.php -> set up DB connections and stuff. Buffers output index.php -> The current page with it's layout, output is buffered. postprocess.php -> Fetches buffer, applies...
19
2239
by: aa | last post by:
Is a PHP variable supposed to be seen in a .js file included into a .php file? I have a client side javascript code stored in a .js file which is included into a PHP file using <script src="filename.js></script> This code initialises a Javascript variable var u="string";
11
3691
by: juglesh | last post by:
at one centraldomain.com, I have central.php, which consists of this: <?php function square($num) { return $num * $num; } ?> at outerdomain.com, I have test.php, which consists of this: <?php include "http://www.centraldomain.com/central.php";
26
2330
by: TomB | last post by:
I have a function on an "included" page. For reasons unknown to me I frequently will get an error - to the effect that the function can't be found. If I hit refresh/F5 it loads the page just fine. It doesn't happen often .. maybe once every 50 pages. It also doesn't happen on any specific page.
7
3870
by: Randell D. | last post by:
Folks, I've found a nice menu piece of javascript that works fine when the code is included entirely inside the html page. However, when I place the javascript code outside, in its own ".js" type file, it doesn't execute. IE6 reports an error "Object expected" line 30, char 1, code 0. This is the BODY tag which I've pasted below (with...
13
3294
by: wylbur37 | last post by:
(This is a re-post of something that apparently did not post correctly the first time, so if there's more than one copy, please ignore the duplicate). I normally use Mozilla 1.4 on Windows XP Pro. As I was developing some test webpages, I discovered that the SRC parameter doesn't seem to work when a path is used with the filename. In one...
16
4429
by: michael | last post by:
Is it possible to get all href URLs contained in a unordered list and place them in an array? Or in fact two different arrays, differently named one for each <ul> group? <ul> <li><a href="lemurs.html">Lemurs</a></li> <li><a href="chameleons.html">Chameleons</a></li> </ul> <ul>
11
15287
by: kk | last post by:
Can any function tell the compiled program executing path? after using the program to open a file from MFC dialog box, the path changes. thks in advance.
3
5287
by: laryten | last post by:
Hi, Is there a way to update the same web page instead of getting a new page each time we click the submit button? The simplest thing to do is to delete the current page (or go back to the previous page) and then redraw the page. There are a few possible solutions: 1. Use the same URL again. But a new page will still be created. 2. Use...
0
7911
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.