MyBB Community Forums

Full Version: Php Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Okay i know i post this before but now i am stuck,

http://www.tutorialfx.com/forums/index.p...opic=13139

i am using that php script to get a random sig.

but no matter how long i look in varous books and sites, i can't restrict one of those sigs to canadian ips. if someone could tell me were to look or better yet a site that has it that would be awesome.

(to reitterate i want one sig to only show to canadians.)
It should be something like this:
<?php

header("Content-type: image/jpeg");
//if the one you only want to show to Canadians is sig 3
$ip=@$REMOTE_ADDR; 
$sig[0] = "sig1.jpg";  
$sig[1] = "sig2.jpg";
$sig[2] = "sig3.jpg";
$sig[3] = "sig4.jpg";
$sig[4] = "sig5.jpg";

$rand_num = rand(0, 4);


$modip = //Set modip to the IP striped down to the part which distinguishes it to Canada.
$upperiplimit = //the upper limit of the ip range of canada
$loweriplimit = //the lower ip range limit of canada

if ($rand_num == 3){
if($modip > $upperiplimit && $modip < $loweriplimit){
while($rand_num == 3)
  {
  $rand_num = rand(0, 4);
  }
}
}

$image = ImageCreateFromJpeg($sig[$rand_num]);
ImageJpeg($image);
ImageDestroy($image);
?>

If you can tell me what distinguishes a Canadian IP i can probably finish it.

Ps. I might have got a bit of the logic in the <'s and >'s wrong, check that.
(2009-03-06, 11:01 PM)_Tim Wrote: [ -> ]It should be something like this:
<?php

header("Content-type: image/jpeg");
//if the one you only want to show to Canadians is sig 3
$ip=@$REMOTE_ADDR; 
$sig[0] = "sig1.jpg";  
$sig[1] = "sig2.jpg";
$sig[2] = "sig3.jpg";
$sig[3] = "sig4.jpg";
$sig[4] = "sig5.jpg";

$rand_num = rand(0, 4);


$modip = //Set modip to the IP striped down to the part which distinguishes it to Canada.
$upperiplimit = //the upper limit of the ip range of canada
$loweriplimit = //the lower ip range limit of canada

if ($rand_num == 3){
if($modip > $upperiplimit && $modip < $loweriplimit){
while($rand_num == 3)
  {
  $rand_num = rand(0, 4);
  }
}
}

$image = ImageCreateFromJpeg($sig[$rand_num]);
ImageJpeg($image);
ImageDestroy($image);
?>

If you can tell me what distinguishes a Canadian IP i can probably finish it.

Ps. I might have got a bit of the logic in the <'s and >'s wrong, check that.

i'm not sure what you mean like country code? CA?

Edit if that not it i have no idea. would this help? http://www.ipaddresslocation.org/ip-address-ranges.php
Well there is no way to get the actual name of the country of origin of your visitors, you have to identify them by the range of IP addresses that belong to Canada. What identifies a Canadian IP?
Ps. I think this might be able to help: http://www.ipaddresslocation.org/ip_rang...ranges.php
(2009-03-06, 11:13 PM)_Tim Wrote: [ -> ]Well there is no way to get the actual name of the country of origin of your visitors, you have to identify them by the range of IP addresses that belong to Canada. What identifies a Canadian IP?
Ps. I think this might be able to help: http://www.ipaddresslocation.org/ip_rang...ranges.php

76.75.95.*

is that it?

http://www.ipaddresslocation.org/ip-address-ranges.php
It might be, where did you get that from? Is that what that ipaddresslocation.org gave you?
Or is that just the first part of your IP address?
Because usually the IP address contains the Country, region and service provider atleast so you need to know exactly what part is the country.
(2009-03-06, 11:19 PM)_Tim Wrote: [ -> ]It might be, where did you get that from? Is that what that ipaddresslocation.org gave you?
Or is that just the first part of your IP address?
Because usually the IP address contains the Country, region and service provider atleast so you need to know exactly what part is the country.

yes that is what Ipaddresslocation gave me.

i have no idea what this is. i am good at building machines not codes :s
Ok cool, can you check that your IP starts with that.
If that IP range is correct this should work:

<?php

header("Content-type: image/jpeg");
//if the one you only want to show to Canadians is sig 3
$ip=@$REMOTE_ADDR; 
$sig[0] = "sig1.jpg";  
$sig[1] = "sig2.jpg";
$sig[2] = "sig3.jpg";
$sig[3] = "sig4.jpg";
$sig[4] = "sig5.jpg";

$rand_num = rand(0, 4);
$canip = '76.75.95.';

if ($rand_num == 3){
if(substr($ip, 9) == $canip){
while($rand_num == 3)
  {
  $rand_num = rand(0, 4);
  }
}
}

$image = ImageCreateFromJpeg($sig[$rand_num]);
ImageJpeg($image);
ImageDestroy($image);
?>
finally worked it out and it doesn't work?


Warning: Cannot modify header information - headers already sent by (output started at /home/themark/public_html/sig/index.php:9) in /home/themark/public_html/sig/index.php on line 11

Warning: imagecreatefromjpeg(sig5.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/themark/public_html/sig/index.php on line 32

Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/themark/public_html/sig/index.php on line 33

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/themark/public_html/sig/index.php on line 34