Activity Stream
48,167 MEMBERS
61104 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 2 of 2
  1.     
    #1
    Banned
    Website's:
    AlibabaHost.com

    Default User redirection based on Location??

    Hi,
    Can any one tell me the html code for User redirection based on Location i.e if any user visit our website usa it should direct them to .us domain instead of .com domain.

    thx
    anuragblr Reviewed by anuragblr on . User redirection based on Location?? Hi, Can any one tell me the html code for User redirection based on Location i.e if any user visit our website usa it should direct them to .us domain instead of .com domain. thx Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Banned
    Website's:
    worldwidexs.com.au
    PHP stores information about the referring URL in one of its global variables - $_SERVER. You can easily access that value using the $_SERVER['HTTP_REFERER']. Now what you have to do is to see if any of the 2 domains is in that HTTP_REFERER variable. You can do this using he preg_match function.

    This is the code that you can use:

    PHP Code: 
    <?
    $referrer 
    $_SERVER['HTTP_REFERER'];
    if (
    preg_match("/site1.com/",$referrer)) {
          
    header('Location: http://www.customercare.com/page-site1.html');
    } elseif (
    preg_match("/site2.com/",$referrer)) {
          
    header('Location: http://www.customercare.com/page-site2.html');
    } else {
          
    header('Location: http://www.customercare.com/home-page.html');
    };
    ?>
    Note, that because of using the header() function that code has to be put on the very top of your PHP page. Header redirect will throw an error if there is something sent to visitors browser before calling it.

    Instead of using $_SERVER['HTTP_REFERER'] you can use $_SERVER['REMOTE_ADDR'] which carries information about visitors IP address. This way you can redirect users based on their IP address. If you detected that someone is trying to hack your web site you can use that PHP redirect to send him to a ?Thank you page?

    PHP Code: 
    <?
    $visitor 
    $_SERVER['REMOTE_ADDR'];
    if (
    preg_match("/192.168.0.1/",$visitor)) {
          
    header('Location: http://www.yoursite.com/thank-you.html');
    } else {
          
    header('Location: http://www.yoursite.com/home-page.html');
    };
    ?>


    I think that shud help you

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 9th Dec 2013, 06:14 PM
  2. How To Sop Redirection ?
    By r@liablehost in forum Technical Help Desk Support
    Replies: 3
    Last Post: 2nd Jan 2011, 11:36 AM
  3. Redirection problem
    By World Life in forum phpBB
    Replies: 3
    Last Post: 15th Dec 2010, 11:17 AM

Tags for this Thread

BE SOCIAL