Jump to content

Redirect Issue


princeofpersia

Recommended Posts

Hi guys, I have a page which is included in all my page, what this page does is getting all ip ranges from database and refirecting users based on their ip address. Issue here is that all type of browsers tell me that there are too many redirections, I have used <?php ob_flush(); ?> & <?php ob_start();?>

for all pages, my friends have also checked it from different computer and network with cleared browser cache and cookies but it is still the same, getting too many redirection error

 

I have the code below and I would appreciate if someone helps me to see what other alternatives are, thank you all in advance

 

 

ERROR:

The page isn't redirecting properly

 

          Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

 

  This problem can sometimes be caused by disabling or refusing to accept

    cookies.

 

 

 

 

and this is the code where ips are checked

 


<?php
ob_start();

// Replace this MYSQL server variables with actual configuration 
$mysql_server = "localhost"; 
$mysql_user_name = "prince"; 
$mysql_user_pass = "gfgjfkdgjlkfdjk"; 

// Retrieve visitor IP address from server variable REMOTE_ADDR 


// Convert IP address to IP number for querying database



// Connect to the database server 
$link = mysql_connect($mysql_server, $mysql_user_name, $mysql_user_pass) or die("Could not connect to MySQL database"); 

// Connect to the IP2Location database 
mysql_select_db("prince") or die("Could not select database"); 
$ip=$_SERVER["REMOTE_ADDR"];
$clearip= str_replace(".", "", $ip);
echo $clearip;
$list=mysql_query("SELECT * FROM ip WHERE $clearip<=endsto AND $clearip>=startfrom") or die("Finding your location failed");

if (mysql_num_rows($list)==0) {

//header("Location: http://www.mydomain.com/country.php"); 

}

else

///////////////////////////------  Countries Redirection Starts Here -----//////////////////////////////////////////////////

while ($row=mysql_fetch_array($list)){

$countrycode=$row['countrycode'];
$countryname=$row['countryname'];	

}

echo $countrycode;
echo $countryname;

if($countrycode==US) {header("Location: http://www.us.mydomain.com"); } 
if($countrycode==GB) {header("Location: http://www.uk.mydomain.com"); }

ob_flush();
?>


 

and this is the example page where i have included it

 

<?php ob_start();?>
<!--Header starts here-->
<?php
include ('http://www.uk.mydomain.com/include/content/header.php') 
?>

<div id="breadcrumbs"><div id="text"><?php include($_SERVER['DOCUMENT_ROOT']."/backlinks.php"); ?></div></div><br/>
<div id="pagetitleholder"><div id="pagetitle"><h1>Create Account</h1></div></div>
<?php include_once ('../../include/config/detect.php') ?>


<!--Footer starts here-->
<?php include ('http://www.uk.mydomain.com/include/content/footer.php') ?>
<?php ob_flush(); ?>

 

thanks

Link to comment
Share on other sites

http://www.phpfreaks.com/forums/index.php?topic=37442.0

 

http://php.net/manual/en/function.header.php

 

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

 

Do not echo or include anything that will echo before a header redirect.

Link to comment
Share on other sites

Thanks for information but even tho when i have it on my first line of code, it again has the same error, one new thing i just found out was that if i change

 

if($countrycode=="US") {header("Location: http://www.us.mydomain.com"); } 
else
if($countrycode=="GB") {header("Location: http://www.uk.mydomain.com"); }

 

to

 

if($countrycode=="US") {header("Location: http://www.us.mydomain.com"); } 
else
if($countrycode=="GB") {header("Location: http://www.us.mydomain.com"); }

 

it redirects me to US subdomain, but if I visit UK page with UK IP it gives me the error.

 

I think there is definit loop going on here but have no idea where.

Link to comment
Share on other sites

If have more can do elseif

 

if($countrycode =="GB") {
header("Location: http://www.uk.mydomain.com");
} elseif($countrycode =="AU" || $countrycode == "AUS") {
header("Location: http://www.au.mydomain.com");
} else {
header("Location: http://www.us.mydomain.com");//so this would be default if country code not found
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.