Results 1 to 13 of 13

Thread: PHP redirection page

  1. #1
    Join Date
    Feb 2010

    Exclamation PHP redirection page

    Hey guys!

    I'm going to state my 'thing' and hopefully somebody can help me, or at least give me a kick for the start.

    I'm building 1 webpage for 3 different public ( one in the US, in the UK and New Zealand ). The thing is that page will be almost the same, with some minor ( or major ) content changes.
    What do I need... Is a PHP script ( working with a cookie ) which automatically catches the visitors IP and sends him to his region ( so if you're from US and you enter the UK address you will be redirected automatically to the US site ). Beside this, I would like to add an exception. Like a special page, which only I'm aware off, where you will get an cookie that allows you to visit any page even if you're from NZ and you want to visit the US page.

    Giant thanks if someone can help me with this ( I'm not quite 'in-love' with cookies and I'm slightly new for PHP as well :P )


  2. #2
    Join Date
    Feb 2010
    This is the variable which is contain visitor's IP
    what you need is making a list of IP from UK, US, example, UK's IPs start with 911.911

    if (preg_match('/^(911\.911\.)/' , $_SERVER[REMOTE_ADDR]))
      header('location: site/uk.php');
    If user from UK want to visit US's page, i have an idea, is that the re-director code will only execute ONE TIME per visitor, so next time user click on "US Page" link they wont be redirected again.

    if (preg_match('/^(911\.911\.)/' , $_SERVER[REMOTE_ADDR]) && !($_SESSION['is_redirected']))
      header('location: site/uk.php');
      $_SESSION['is_redirected'] = TRUE;
    Hope this help

  3. #3
    Join Date
    Feb 2010
    you're a life saver !

    the only thing that still needs to be done is the think when an UK IP wants to get to the US page. I would really like that to be automatic and the cookie thing sounds quite nice ...

    But mate, thank you soooo much for your help ( now I have a start, at least )

  4. #4
    Join Date
    Jan 2009
    I would use a "splash" screen on the first visit to allow the user to select the region they want. One instance where automatically checking for them may not be a good idea is when someone is on vacation in another region or if their proxy server is located in another region but they may physically be somewhere else. I would then store their selection in a cookie but still provide a way to re-select the region if needed (for example if someone moves or wishes to access another region for any reason).

  5. #5
    Join Date
    Feb 2010
    I know what you mean, but the thing is that the US are not allowed to see the UK due to copyright restrictions, the UK can't see the NZ for the same reason and so on. So visitors need to stick on their region

    That's why I would like to make this automatic, without splash page ( that was my first idea, but it's not the right choice in this case ).

  6. #6
    Join Date
    Jan 2009
    I understand about copyright...you just have to realize that ip-redirection is not perfect and there could be many cases where the redirection will not go to the correct region. What happens when an American is traveling through the UK?

  7. #7
    Join Date
    Feb 2010
    if he's going to use local internet ( UK ISP ), he will see the UK page. He is allowed to see the UK if he's on British land ( and the same thing goes for each country )

  8. #8
    Join Date
    Jan 2009
    Here is another hypothetical...for example in China right now many people are viewing the internet through proxy servers in other regions. Your auto-detect script would display the wrong region for those users.

  9. #9
    Join Date
    Feb 2010
    Those whom use proxy ( Chinese, American, British, etc ) can view any of the pages, that's their problem. My hands are tied because of that stupid copyright and stupid requirements.

    Ah and btw... the rest of the world ( beside US and NZ ) are going to see the UK page

  10. #10
    Join Date
    Jan 2009
    Makes sense. I just wanted to make sure you were aware of the potential pitfalls with automatic detection. There are many geo2ip services if you do a quick search. I can't think of any that are free though (I also didn't search very hard either).

  11. #11
    Join Date
    Feb 2010
    Oh thanks for all the help mate. I was sure of my decision, that's why I posted this thread. I'm going to take a look to the geo2ip services and hopefully something will be found!


  12. #12
    Join Date
    Nov 2008
    Quote Originally Posted by namduong8889 View Post
    ...UK's IPs start with 911.911...
    No IP address starts with 911. IP addresses are 4 bytes long, and a byte can only store 0-255.

    @OP, if you want to determine location from IP address your best bet is to use a database of IP addresses to counties. I've used this one in the past with some success.

    You can also improve the detection of real IP sometimes by tracing back through proxies. Obviously doesn't help for transparent proxies but it might be a bit more accurate over all:

    PHP Code:
    function get_ip() {
        switch (
    false) {
            case empty(
            case empty(

    Last edited by Mindzai; 02-18-2010 at 09:49 AM.

  13. #13
    Join Date
    Feb 2010

    The thing above with the 911 was only an example, I got the point .

    I do really want to thank you for the list. I think I'm going to use that one, if you say that the thing works okay. I'm worried that much about proxies, because the real target of the web page doesn't include people whom use proxies .


Thread Information

Users Browsing this Thread

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.21838 seconds
  • Memory Usage 2,978KB
  • Queries Executed 15 (?)
More Information
Template Usage (35):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (13)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (13)postbit
  • (13)postbit_onlinestatus
  • (13)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates