473,471 Members | 2,613 Online
Bytes | Software Development & Data Engineering Community
Create 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 3360
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.example.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.example.com/script.php?host=http://local.example.com/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.example.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.example.com/script.php?host=http://local.example.com/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.com
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.example.com/script.php?host=http://local.example.com/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=bar"),
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.example.com/script.php?host=http://local.example.com/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.com
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.remotedomain.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
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...
19
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...
11
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:...
26
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...
7
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"...
13
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...
16
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...
11
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
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...
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
jinu1996
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.