Welcome to WebmasterWorld Guest from 23.22.46.195

Forum Moderators: open

Please tell me why this doesn't work

   
4:58 pm on Mar 15, 2013 (gmt 0)



Guys,

I need your help! Please tell me why my script won't redirect but the script I have below the line does. I think it has something to do with the variables but I would appreciate any help you guys can offer!

My script that doesn't redirect!

<script language="JavaScript" src="http://beaman-auto.com/ip2.php"></script>

<script type="text/javascript">
// IP Redirect
if (Ip=="63.243.66.174"){location.replace("http://www.example.com/security.html")
}
</script>


-----------------------------------------------------------

The Script that does redirect

<script language="JavaScript" src="http://scripts.hashemian.com/js/visitorIPHOST.js.php"></script>

<script type="text/javascript">
// IP Redirect
if (VIH_HostIP=="63.243.66.174"){location.replace("http://www.example.com/security.html")
}
</script>


------------------------------------------------------------

Here's my php code from the beaman-auto.com/ip2.php link.

<?php

function getRealIpAddr() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
//check ip from share internet
$ip=$_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
//to check ip is pass from proxy
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
?>

<?php
$ip = getRealIpAddr();
$VIH_HostIP = $ip;

$VIH_DisplayFormat = 'You are visiting from:<br>IP Address: ' . $ip . '<br>Host: ' . $VIH_HostIP . '"';
echo 'VIH_DisplayFormat = "' . $VIH_DisplayFormat . '"';
?>
<script type="text/javascript">
var Ip = "<?php echo $ip; ?>";
</script>
6:33 pm on Mar 15, 2013 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



ip2.php is included in your markup as though it was a script file, but you are including HTML markup in it instead.

The output of your non working version looks like this:

VIH_DisplayFormat = "You are visiting from:<br>IP Address: 0.0.0.0<br>Host: 0.0.0.0""<script language="javascript">
Ip = "0.0.0.0";
</script>


Instead, you'll need to get rid of that echo statement, as well as the opening and closing script tags so that when you include it, the output is valid JavaScript:


<?php

function getRealIpAddr() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
//check ip from share internet
$ip=$_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
//to check ip is pass from proxy
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
?>

<?php
$ip = getRealIpAddr();
$VIH_HostIP = $ip;

$VIH_DisplayFormat = 'You are visiting from:<br>IP Address: ' . $ip . '<br>Host: ' . $VIH_HostIP . '"';
//echo 'VIH_DisplayFormat = "' . $VIH_DisplayFormat . '"';
?>
var Ip = "<?php echo $ip; ?>";
8:02 pm on Mar 15, 2013 (gmt 0)



That works perfect Fotiman. Thank you so much for your help and guidance.

Is it difficult to put an array in the PHP file that includes the ip addresses I want to redirect and have the Javascript to check those and basiclly if there is a match to redirect that visitor?

I'll tell you a bit about my situation. When I run specials on my website, my competitors in my area shop the site and basically copy my specials and take content. The problem is my website provider will not allow me to add/edit any javascript on the site. I can however control the PHP file which is hosted on my server. What I would love to be able to do is submit the javascript to my website provider and as I get each competitors IP address, add it into the array in the PHP file that I can control.

Is this possible?
8:33 pm on Mar 15, 2013 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



It's not difficult to check an array of items for a particular value. The question, though, is whether or not it's worth trying to do. It's easily bypassed. All the visitor would need to do is disable JavaScript in their browser. Alternatively, there are sites online that "anonymize" your request (basically they view your site through a proxy so from your server's perspective it will not see the true IP address of the visitor). There's not much you can really do to truly prevent data that appears on the web from being copied.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month