For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > August 2006 > Serving a website based on source internet address ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Serving a website based on source internet address ?
Skybuck

2006-08-29, 6:57 pm

Hello,

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

I would like to keep the script as simple as possible and it should
replace the index.php.

The script could look something like this 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; // load/show RedIndex.htm
end;

Is this possible with php ?

Bye,
Skybuck.

Jerry Stuckle

2006-08-29, 6:57 pm

Skybuck wrote:
> Hello,
>
> Based on the source internet address a different version of the website
> should be presented/served to the user/browser.
>
> I would like to keep the script as simple as possible and it should
> replace the index.php.
>
> The script could look something like this 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; // load/show RedIndex.htm
> end;
>
> Is this possible with php ?
>
> Bye,
> Skybuck.
>


Sure.

<?php

switch ($_SERVER['REMOTE_ADDR']) {
case '143.3.5.1':
header('Location: BlueIndex.htm');
break;
case '124.6.15.7':
header('Location: RedIndex.htm');
break;
default:
header('Location: DefaultIndex.htm');
}
?>

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Skybuck

2006-08-30, 6:57 pm

> <?php
>
> switch ($_SERVER['REMOTE_ADDR']) {
> case '143.3.5.1':
> header('Location: BlueIndex.htm');
> break;
> case '124.6.15.7':
> header('Location: RedIndex.htm');
> break;
> default:
> header('Location: DefaultIndex.htm');
> }
> ?>


Hello,

Is it possible to use an "or" operator in php ? I only want to specific
the location twice, since there are only two versions of the website.
However there can be many ip's to include, for example in pseudo code:

if (RemoteAddress = '192.5.6.7') or
(RemoteAddress = '192.5.6.8') or
(RemoteAddress = '192.4.6.8') or
(RemoteAddress = '112.44.6.8') then
begin
header('Location: RedIndex.htm');
end else
begin
header('Location: BlueIndex.htm');
end;

Is this possible in PHP ?

Bye,
Skybuck.

Skybuck

2006-08-30, 6:57 pm


Skybuck schreef:

>
> Hello,
>
> Is it possible to use an "or" operator in php ? I only want to specific
> the location twice, since there are only two versions of the website.
> However there can be many ip's to include, for example in pseudo code:
>
> if (RemoteAddress = '192.5.6.7') or
> (RemoteAddress = '192.5.6.8') or
> (RemoteAddress = '192.4.6.8') or
> (RemoteAddress = '112.44.6.8') then
> begin
> header('Location: RedIndex.htm');
> end else
> begin
> header('Location: BlueIndex.htm');
> end;
>
> Is this possible in PHP ?


I'd still like to know the answer to this one ;) I tried the "or"
operator but it doesn't seem to work.

I think I found the solution looking at your post, the same effect can
probably be achieved with a case fall through. Leaving the break out
could achieve this effect if php is a case-fallthrough-language ;)

I shall try this code next:

<?php
switch ($_SERVER['REMOTE_ADDR']) {
case '143.3.5.1':
case '142.3.5.1':
case '146.3.7.1':
case '141.3.5.1':
case '123.7.5.10':
header('Location: BlueIndex.htm');
break;
case '124.6.15.7':
header('Location: RedIndex.htm');
break;
}
?>

Bye,
Skybuck.

Jerry Stuckle

2006-08-30, 6:57 pm

Skybuck wrote:
>
>
> Hello,
>
> Is it possible to use an "or" operator in php ? I only want to specific
> the location twice, since there are only two versions of the website.
> However there can be many ip's to include, for example in pseudo code:
>
> if (RemoteAddress = '192.5.6.7') or
> (RemoteAddress = '192.5.6.8') or
> (RemoteAddress = '192.4.6.8') or
> (RemoteAddress = '112.44.6.8') then
> begin
> header('Location: RedIndex.htm');
> end else
> begin
> header('Location: BlueIndex.htm');
> end;
>
> Is this possible in PHP ?
>
> Bye,
> Skybuck.
>


Did you try looking this up in the manual?

Yes, it is possible - see
http://www.php.net/manual/en/langua...rs.logical.php.

But your problem is in how your if statement is constructed. See
http://www.php.net/manual/en/langua...l-structures.if


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Norman Peelman

2006-08-30, 6:57 pm

"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:E8WdnQrOCrCsUGjZnZ2dnUVZ_oednZ2d@co
mcast.com...
> Skybuck wrote:
>
> Did you try looking this up in the manual?
>
> Yes, it is possible - see
> http://www.php.net/manual/en/langua...rs.logical.php.
>
> But your problem is in how your if statement is constructed. See
>

http://www.php.net/manual/en/langua...l-structures.if
>
>


How about 'in_array()'?

$ip_arr = array('192.5.6.7',
'192.5.6.8',
'192.4.6.8',
'112.44.6.8'
);
if (in_array($_SERVER['REMOTE_ADDR'], $ip_arr))
{
header('Location: RedIndex.htm');
}
else
{
header('Location: BlueIndex.htm');
}

.... not sure if you need to use the full domain name in the header function
or not.

Norm


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com