Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

$base_url special meaning?

by punch_card_don (Curate)
on Nov 04, 2010 at 17:12 UTC ( #869516=perlquestion: print w/replies, xml ) Need Help??

punch_card_don has asked for the wisdom of the Perl Monks concerning the following question:

Mordant Monks,

Scratching my head over this. This snippet is in a script accessed over the web:

print "<p>base_url = $base_url\n"; $base_url = 'http://123.456.789.000'; print "<p>base_url = $base_url\n";
which usually correctly produces
base_url = base_url = http://123.456.789.000
But one user is accessing my script through a proxy server. (EZProxy, what else?) When they access it, they get:
base_url = base_url =
The variable $base_url is hard-coded in the script. The fact of coming from a proxy server should have zero effect on that. Now, this script uses only one module, CGI.

Am I unwittingly referencing a special variable or something that's overridding my hard-coded value?



Immediately following the above snippet, there comes:

print "<p>at A called_from = $called_from\n"; print "<p>at A base_url = $base_url\n"; @url_parts = split (/$base_url.*?\// ,$called_from); print "<p>at B base_url = $base_url\n"; for $i (0 .. $#url_parts) { print "<br>url_parts[$i] = $url_parts[$i]\n"; }
where "called_from" is the url of the referring page that called the script, set earlier in the script. Again, when I access it, it correctly outputs:
at A called_from = http://123.456.789.000/mysubfolder/mypage.htm at A base_url = http://123.456.789.000 at B base_url = http://123.456.789.000 url_parts[0] = url_parts[1] = mysubfolder/mypage.htm
but when my proxied friend tries it, they get
at A called_from = +e.htm at A base_url = at B base_url = url_parts[0] = url_parts[1] =
So, OK, I don't get why it's substituting their proxy domain for the hard-coded $base_url - but considering the value of $called_from, url_parts1 should have been the same mysubfolder/mypage.htm as I get - no? Makes me think there's really something weird going on with this $base_url variable.

Time flies like an arrow. Fruit flies like a banana.

Replies are listed 'Best First'.
Re: $base_url special meaning?
by MidLifeXis (Monsignor) on Nov 04, 2010 at 17:22 UTC

    Is it possible that the EZProxy is rewriting anything that looks like a URL as a port on the proxy server? Just glancing at the website makes me think that this may be the case.

    Update: How are you identifying the mimetype of the returned document? Perhaps the proxy is not identifying that this is not HTML, javascript, or xml, and is rewriting it as such. Search for rewrite in the documentation.


      Looking into it, MLX. You got me thinking about a proxy-related environment variable or something...
        but that will only come into play if $base_url is somehow special. if it's a plane jane variable, then there's no reason for anything to affect such simple code whereby a variable is assigned and immediately printed.
        the hardest line to type correctly is: stty erase ^H

        I don't think that is what I said. If I understand you correctly, your user behind the proxy is seeing this behavior. If no one else is seeing this behavior, I would be more likely to check out what is unique with that environment first.

        Since that user is behind a proxy that has the capability to rewrite urls so that they are directed back to a port on the proxy server, I would guess that the probability is quite high that this setting is active on his proxy server.

        What mimetype are you using to send the file? According to the documentation cited in my previous post, if the document is HTML, javascript, or XML, URLs will be rewritten by the proxy server. I did not see a definitive statement as to what would happen in other cases.

        What I am guessing is happening is this:

        1. You are sending the value of your $baseurl variable to the user via the EZProxy.
        2. The EZProzy is rewriting your URL to something that refers to the proxy server itself
        3. The user sees the address for the EZProxy instead of your address.


Re: $base_url special meaning?
by punch_card_don (Curate) on Nov 05, 2010 at 20:26 UTC
    OMG - I don't know who's dumber, me or EZProxy.

    It finally occurred to me - and here it is for future reference.

    When the proxy user calls the script, the resulting html output is fed back to him through the proxy server. EZProxy uses a predefined list of absolute urls that it should identify and rewrite on a page. Well, apparently it's not smart enough to distinguish between an actual link and some text on the page that matches one of its predefined urls.

    I modified the script to send my debugging output to a local file instead of stdout, and lo and behold, there's

    base_url = http://123.456.789.000

    everywhere, unmolested.

    Just shoot me now.

    Thanks again for the help.

    Time flies like an arrow. Fruit flies like a banana.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://869516]
Approved by ELISHEVA
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2021-01-21 08:47 GMT
Find Nodes?
    Voting Booth?