Popup scripts but only to certain visitors
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- Popup scripts but only to certain visitors
Popup scripts but only to certain visitors
28-03-2008 5:15 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator

For example: a visitor from the PlusNet IP range visited my site, it shows the popup, from anywhere else it does not.
Re: Popup scripts but only to certain visitors
28-03-2008 11:29 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Most can be found at http://javascript.internet.com/user-details/
With SSI enabled this should work:
<!--#set var="ip" value="$REMOTE_ADDR" -->
<!--#if expr="$ip = /123.123.123.123/" -->
<script type="text/javascript">
window.alert("Welcome to the forums, Huntress.");
</script>
<!--#endif -->
<?php
if($_SERVER['REMOTE_ADDR'] == '123.123.123.123'){
echo '<script type="text/javascript">
window.alert("Welcome to the forums, Huntress.");
</script>';
}
?>
get ip
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
// http://www.kdcgrohl.com
// Depending on your server set-up,
// you may need to use the ".shtml"
// extension [instead of the "html"
// or "htm"] as the script uses Server
// Side Includes. To display in the
// title bar, exclude the
//"<title></title>" code from the page.
// This part gets the IP
var ip = '<!--#echo var="REMOTE_ADDR"-->';
// This part is for an alert box
alert("Your IP address is "+ip);
// This part is for the status bar
window.defaultStatus = "Your IP address is "+ip;
// This part is for the title bar
document.write("<title>Your IP address is "+ip+"</title>");
// End -->
</script>
<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size: 1.09 KB -->
http://javascript.internet.com/user-details/
Re: Popup scripts but only to certain visitors
30-03-2008 12:16 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator

I would use PHP and make it much more dynamic (behind the scenes),
I would use JavaScript purely to produce the popup / display the text.
JavaScript, is fine for actually producing the Popup Message Box / Window / what ever as it's supported widely.
Use PHP to process Headers Sent by the Web Browser,
to provide information such as Language ($_SERVER["HTTP_ACCEPT_LANGUAGE"]),
IP Address ($_SERVER["REMOTE_ADDR"]) and what not.
(To check by IP range is alittle more tricky, but you can quite easily process an IP in 4 numerical parts, check each one against a range.
I can try and provide an example if you wish)
If all parameters are TRUE, provide the popup only when needed

Jim,
Re: Popup scripts but only to certain visitors
31-03-2008 11:53 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
The reason was there may be more than one or a complete range that I would want to display the pop to.(went for a html page as a popup rather than just a window.
Re: Popup scripts but only to certain visitors
31-03-2008 10:45 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
$IPS = Array();
$IPS[0]="xxx.xxx.xxx.xxx";
...
etc
..
for($i=0;$i<count($IPS);$i++){
//checking code & logic
}
So that it checks IP's from a defined list..
Where the list comes from, could be database driven.. file.. how ever you wish..
Jim,
Re: Popup scripts but only to certain visitors
01-04-2008 12:00 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: Popup scripts but only to certain visitors
02-04-2008 8:42 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
123.123.0.0 or 123.123.123.0 upto the top of the range, how would I do that from
[tt]<?php
if($_SERVER['REMOTE_ADDR'] == '123.123.123.123'){
echo '<script type="text/javascript">
window.open("popup.html");
</script>';
}
?> [/tt]
Not usre if I need the subnet mask on the end? /255.255.0.0
you may have answered the question with the array but that's a bit past my abilities at the moment.
Re: Popup scripts but only to certain visitors
04-04-2008 12:41 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
along the lines of this if you plan to use 'wild cards' ...
<?php
//===========Dev-Center============
//=By J4M32 - jim@dev-center.co.uk=
//===========Dev-Center============
//Value set and checked later ...
$IPconfirm = 0;
//Explode the IP by the . character
$IPExp = explode('.',$_SERVER['REMOTE_ADDR']);
// define your IP 'Ranges' (Only by Wild cards)...
$IPList = Array();
$IPList[0] = '123.123.123.*';
$IPList[1] = '221.221.*.*';
//for every IP we've got in the list...
for($i=0;$i<count($IPList);$i++){
//explode the IP range into component parts..
$ExpIPList = explode('.',$IPList[$i]);
//for each part of the IP ...
for($j=0;$j<count($ExpIPList);$j++){
//compare them ...
//Logic handeling the '*' Wild Cards... are they the 'same'?
if(($ExpIPList[$j] == $IPExp[$j]) || $IPExp[$j] == "*"){
$IPconfirm++;
}
}
//safety against using "dirty" Arrays...
unset($ExpIPList);
}
//end of for loops
//did all 4 parts 'match'?
if($IPconfirm == 4){
echo '
<script type="text/javascript">
window.open("popup.html");
</script>';
}
?>
if you plan to define a more accurate 'value specific range',
that will require more perocessing and internal syntax to the strings,
to make life alittle bit easier for processing it and identifying...
<?php
//===========Dev-Center============
//=By J4M32 - jim@dev-center.co.uk=
//===========Dev-Center============
//Value set and checked later ...
$IPconfirm = 0;
//Used for Ranges later...
$ValueRange = Array();
//abosolute values - directly inbetween the two vlaues or numerically exlusive case?
$InclusiveCompare = 1;
//Explode the IP by the . character
$IPExp = explode('.',$_SERVER['REMOTE_ADDR']);
// define your IP 'Ranges' (Only by Wild cards)...
$IPList = Array();
$IPList[0] = '123.123.123.128-255';
$IPList[1] = '221.221.96;128-255.*';
//for every IP we've got in the list...
for($i=0;$i<count($IPList);$i++){
//explode the IP range into component parts..
$ExpIPList = explode('.',$IPList[$i]);
//for each part of the IP ...
for($j=0;$j<count($ExpIPList);$j++){
//if there are any ';' breaks ...
if(strpos(';',$ExpIPList[$j]) > 0){
//explode them out...
$ExpIPListValues = explode(';',$ExpIPList[$j]);
//check for specific value ranges..
for($k=0;$k<count($ExpIPListValues);$k++){
//are there any defined sub ranges?
if(strpos('-',$ExpIPListValues[$k]) > 0){
//split out the '-' defined ranges..
$ExpIPListSubranges = explode('-',$ExpIPListValues[$k]);
//for each range found
for($l=0;$l<count($ExpIPListSubranges);$l++){
//blah
$ValueRange[$l] = $ExpIPListSubranges[$l];
//which is the upper bound?
if($ValueRange[0] > $ValueRange[1]){
$Upper = $ValueRange[0];
$Lower = $ValueRange[1];
}else{
$Lower = $ValueRange[0];
$Upper = $ValueRange[1];
}
//if it's in-between the range accept it...
if(($IPExp[$j] > $Lower) && ($IPExp[$j] < $Higher)){
$IPconfirm++; //set the field true...
}
//do we want right up to the range defined?
if($InclusiveCompare == 1){
//is it exactly equal to the lower / higher value?
if(($IPExp[$j] == $Lower) || ($IPExp[$j] == $Higher)){
$IPconfirm++; //set the field true...
}
}
//clears up dirty values
unset($Upper);
unset($Lower);
}
}else{ //otherwise.. must be just a fixed value..
//is it equal?
if($ExpIPList[$j] == $ExpIPListValues[$k]){
$IPconfirm++; //set the field true...
}
}
}
}else{ //otherwise..
//compare them - Logic handeling the '*' Wild Cards... are they the 'same'? / are they exactly equal...
if(($ExpIPList[$j] == $IPExp[$j]) || ($IPExp[$j] == "*")){
$IPconfirm++; //set the field true...
}
}
}
unset($ExpIPList);
}
//end of loops
//did all 4 parts 'match'?
if($IPconfirm == 4){
echo '<script type="text/javascript">
window.open("popup.html");
</script>';
}
?>
Where...
xxx = Integer - single value...
xxx = Integer;Integer;Integer - set of values...
xxx = Integer-Integer; - range of values...
*Thinking out of the box ... Regular Expressions come to mind?
not certain of how to impliment those in this particular case but, could save a few lines*
Quite a lengthy post.
Code bundles in a ZIP.
Here
Hope one of those was what you were after ...
Jim,
Re: Popup scripts but only to certain visitors
04-04-2008 12:38 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator

Re: Popup scripts but only to certain visitors
04-04-2008 6:37 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
sorry it's abit lengthy,
it's the easiest way I could think of doing it.

Hope it all works for what you were after

Jim,
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- Popup scripts but only to certain visitors