473,288 Members | 1,693 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,288 software developers and data experts.

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 3352
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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.