[colug-432] virtual hosts based on ip

Keith Larson klarson at k12group.net
Wed Oct 14 13:49:57 EDT 2015


This is for a PHP based site, so this is extremely helpful.  Thank you.
 >>> R P Herrold <herrold at owlriver.com> 10/14/2015 1:39 PM >>>
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
_______________________________________________
colug-432 mailing list
colug-432 at colug.net
http://lists.colug.net/mailman/listinfo/colug-432
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.colug.net/pipermail/colug-432/attachments/20151014/13b873d6/attachment-0001.html 


More information about the colug-432 mailing list