[colug-432] virtual hosts based on ip
R P Herrold
herrold at owlriver.com
Wed Oct 14 13:39:16 EDT 2015
On Wed, 14 Oct 2015, Angelo McComis wrote:
> Honestly, I think you have set yourself down a path where this will be difficult to support and maintain.
> Give each client a unique sub-url and still authenticate them by IP if you want. But don't make it complicated by trying to auto route them.
is there a purpose to unsolicited advice and prediction of
gloom? The matter is trivially done with the REMOTE_ADDR
variable and a header() command in PHP, and any mature CGI
environment
I'll poke at a proof of concept backed (by a database so that
it is readily altered as to the redirect page by a site
administrator). Static coding is even easier (load an array
with IP's to go to the execption page, test if the REMOTE_ADDR
is in_array(), and alternatively fall to a different header()
Here is real code to that effect. Problem is that it mixes
data (the IP / URL pairs, and code, which is not usually a
very scalable approach, along with otehr reasons
<?php
# COLUG question solution 20151014
# Copyright (c) 2015, R P Herrold, Columbus OH
# License GPLv3+
# reports to: info at owlriver.com
$SPECIALS = array();
$IGNORE_TLD[] = "127.0.0.1";
$IGNORE_TLD[] = "12.45.67.89";
#
$DEFAULT_URL = "http://www.cnn.com/";
$SPECIAL_URL = "http://www.foxnews.com/";
#
$ISFROM = $_SERVER('$REMOTE_ADDR');
# no need to defang as this is a trusted system value
if (in_array($ISFROM ,$SPECIALS)) {
header('Location: ' . $SPECIAL_URL);
}
header('Location: ' . $DEFAULT_URL);
?>
all done
-- Russ herrold
More information about the colug-432
mailing list