Serving a website based on internet source address ?

S

Skybuck

Hello,

Based on the source internet address a different version of the website

should be presented/served to the user/browser.

For example in pseudo code:

if SourceAddress = '143.3.5.1' then
begin
ShowBlueWebsite; // Load/Show BlueIndex.htm
end else
if SourceAddress = '124.5.15.7' then
begin
ShowRedWebsite; // LoadShow RedIndex.htm
end;

Is this possible with perl ? is there any source code available to do
this trick ?

Bye,
Skybuck.
 
J

J. Gleixner

Skybuck said:
Hello,

Based on the source internet address a different version of the website

should be presented/served to the user/browser.

For example in pseudo code:

if SourceAddress = '143.3.5.1' then
begin
ShowBlueWebsite; // Load/Show BlueIndex.htm
end else
if SourceAddress = '124.5.15.7' then
begin
ShowRedWebsite; // LoadShow RedIndex.htm
end;

Is this possible with perl ? is there any source code available to do
this trick ?

It seems like a simple 'redirect', which would take only a few lines of
code, in any language.

Probably better to do this from your Web server, or via JavaScript, and
you may discuss that in a newsgroup for whatever server you're running
or one for JavaScript.

With a CGI processing the request, you could send a "redirect" header,
which would redirect the browser to a different URL, however that would
mean that the page is being generated by a CGI in the first place. If
that's the case, and you're using perl, look for 'redirect' and
'remote_host' in:

perldoc CGI

Otherwise, read the documentation for your Web server and get help in a
more appropriate newsgroup.
 
T

Tad McClellan

Skybuck said:
Based on the source internet address a different version of the website
should be presented/served to the user/browser.

For example in pseudo code:

if SourceAddress = '143.3.5.1' then
begin
ShowBlueWebsite; // Load/Show BlueIndex.htm
end else
if SourceAddress = '124.5.15.7' then
begin
ShowRedWebsite; // LoadShow RedIndex.htm
end;

Is this possible with perl ?

Yes.


is there any source code available to do
this trick ?


If you know any Perl, it is so trivial that I doubt anyone
would package it up.

You need to write 5 or 10 lines of Perl code to do that.


http://learn.perl.org
 
A

alpha_beta_release

if SourceAddress = '124.5.15.7' then

And if you mean technical thing of how to get the address, look for
ENVironment variables
or some CGI modules may help (CGI.pm etc)
 
G

Gunnar Hjalmarsson

J. Gleixner said:
With a CGI processing the request, you could send a "redirect" header,
which would redirect the browser to a different URL, however that would
mean that the page is being generated by a CGI in the first place. If
that's the case, and you're using perl, look for 'redirect' and
'remote_host' in:

perldoc CGI

What if it's a high traffic web site? CGI.pm is a heavyweight module,
and I would advise against using it for a redirect CGI script.

#!/usr/bin/perl
%redir = ('143.3.5.1' => 'BlueIndex', '124.5.15.7' => 'RedIndex');
print 'Location: /', $redir{ $ENV{REMOTE_ADDR} } || 'index', ".htm\n\n";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,647
Latest member
NelleMacy9

Latest Threads

Top