Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call the script *.php?c= with only one page

Status
Not open for further replies.

indiantown

Technical User
Apr 29, 2005
25
US
Hello All,

I am using the below script to create redirection of my page visitors as per their ip address,

<?php
$v=0;$f=0;$n=array();

if(isset($HTTP_GET_VARS['ip'])){
$ip=$HTTP_GET_VARS['ip'];}
else{$ip='10.1.1.10';}

$ip=sprintf("%u",ip2long($ip));
while(strlen($ip)<10){$ip='0'.$ip;}
$h=opendir($crdr);
while($e=readdir($h)){
$o=(int)$e;if(strlen($o)>5){
$n[$f]=$e;$f++;}}closedir($h);
sort($n);

$o=count($n)-1;$d=$n[$o];
for($j=0;$j<$o;$j++){if($ip>=$n[$j]&&$ip<$n[$j+1]){$d=$n[$j];break;}}

$d=$crdr.'/'.$d;$q=fopen($d,"r");
while(!feof($q)){$r=fgets($q,32);
$a=substr($r,0,9);$b=substr($r,10,19);$c=substr($r,20);
if($ip>=$a&&$ip<=$b){$v=1;break;}}
fclose($q);

if($v==0){print "window.location='$default'";}
else{$cc=strtolower($c);$cc=str_replace("\n","",$cc);
if($cc=='gb'){$cc='uk';}
if($cc=='in'){$cc='in';}
if($cc=='fr'){$cc='fr';}
if($cc=='de'){$cc='de';}
$path=set_path($cc);
if(is_file($path)||is_dir($path)){print "window.location='$path'";}
else{print "window.location='$default'";}}
?></script>


means if a person signs from UK they would get redirected to UK page instead of US page.

What I need help is that how I can use one page and call the script in this way: page.php?c=en or page.php?c=cn etc otherwise I would have to keep on creating pages for each country.

Appreciate some help and direction.

regards
 
The variable "c" can be accessed as $_GET['c']. Then you can do what you want. Maybe something like

<?php

switch($_GET['c']) {
case "en":
... english ...
break;
case "cn":
... canadian ...
break;
default:
... something else ...
}

?>
 
Does not work, the complete script is below which I am using... please help me where and what changes I should make.

<?php

$crdr='/'; // set a correct RELATIVE path


function set_path($cc){return "test-$cc.php";}
$default="test-us.php";

$pv=phpversion();$pv=substr($pv,0,1);if($pv>3){$REMOTE_ADDR=$HTTP_SERVER_VARS['REMOTE_ADDR'];}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "<html xmlns=" lang="en">
<head>
<title><?php print $SERVER_NAME; ?> </title>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />

<script type="text/javascript"><?php
$v=0;$f=0;$n=array();

if(isset($HTTP_GET_VARS['ip'])){
$ip=$HTTP_GET_VARS['ip'];}
else{$ip='10.1.1.10';}

$ip=sprintf("%u",ip2long($ip));
while(strlen($ip)<10){$ip='0'.$ip;}
$h=opendir($crdr);
while($e=readdir($h)){
$o=(int)$e;if(strlen($o)>5){
$n[$f]=$e;$f++;}}closedir($h);
sort($n);

$o=count($n)-1;$d=$n[$o];
for($j=0;$j<$o;$j++){if($ip>=$n[$j]&&$ip<$n[$j+1]){$d=$n[$j];break;}}

$d=$crdr.'/'.$d;$q=fopen($d,"r");
while(!feof($q)){$r=fgets($q,32);
$a=substr($r,0,9);$b=substr($r,10,19);$c=substr($r,20);
if($ip>=$a&&$ip<=$b){$v=1;break;}}
fclose($q);

if($v==0){print "window.location='$default'";}
else{$cc=strtolower($c);$cc=str_replace("\n","",$cc);
if($cc=='an'){$cc='an';}
if($cc=='au'){$cc='au';}
if($cc=='ca'){$cc='ous';}
if($cc=='cz'){$cc='ous';}

$path=set_path($cc);
if(is_file($path)||is_dir($path)){print "window.location='$path'";}
else{print "window.location='$default'";}}
?></script></head><body></body>
</html>
 
My first piece of advice you is to indent your code. Particularly if you want someone else to look at it and figure out the code.

My second piece of advice is to use more explicit variable names. Particularly if you want someone else's advice on your code.


I understand that $crdr holds a directory name and that your script first opens that directory and reads all the entries. There appear to be a set of files in that directory with numerical names.

Beyond that, I don't know.

lgarner has given you the best advice. The only way your script can get the input from the URL and react accordingly is to examine $_GET.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top