Results 1 to 7 of 7

Thread: Autoclose if visitor comes via certain site?

  1. #1
    Join Date
    Mar 2007
    Location
    UK
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Autoclose if visitor comes via certain site?

    Hey Guys,

    I have a client with a website that someone else (annoying) has linked to via his own website trying to affiliate himself with the organisation. The client doesn’t want anything to do with him.

    Is it possible to autoclose our webpage if the user comes via this dodgy dude's website?

    Rusty

  2. #2
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    You can only redirect the page, closing the window isnt nice.

    You need to check the referer via php, so this
    <?php
    if (strstr($_SERVER[HTTP_REFERER],"URL")) {
    echo"<meta http-equiv=\"refresh\" content=\"1;URL\" />";
    die();
    } ?>
    would go at the top of your page, switching out the red parts for the denied domain
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    $_SERVER[HTTP_REFERER]
    Don't rely on the PHP parser to convert undefined constants to strings.
    Code:
    echo"<meta http-equiv=\"refresh\" content=\"1;URL\" />";
    Don't use <meta> refreshes when real HTTP redirection is more reliable (and must be obeyed according to the HTTP specification, unlike <meta> elements, which may be ignored). Also, don't assume XHTML. Only in a few cases is it appropriate for the webmaster to use XHTML.
    would go at the top of your page, switching out the red parts for the denied domain
    No, it would go inside the <head>, before any other elements (except other <meta> elements). Also, redirecting the user to the main page of the site whence they just came would cause much confusion. Instead, redirecting to a page explaining the situation and the relationship (or lack thereof) would be beneficial, from which page they could then carry on to view your site if they wished.
    Code:
    <?php
      if(strpos($_SERVER['HTTP_REFERER'], 'URL') !== false)
        die(header('Location: http://www.mysite.com/warning-this-site-is-not-affiliated-with-us.html'));
    ?>
    That would go at the top of your page. Also note that this isn't completely reliable, since some firewalls strip Referer headers.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Use htaccess - i heard its possible i think

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yes, a .htaccess file or equivalent would be a neater solution.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Mar 2007
    Location
    UK
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the help guys, really appreciate it

    I agree that redirecting the user would be a more polite option. However, the page/site is not php though so can a redirect be done through something like javascript?

    A standard redirect is:
    Code:
    <script>
        location = "http://www.thisisme.co.uk/index.html";
    </script>
    But I am not sure how to get it to run this only if the user has come via a certain url.

    Cheers,

    Rusty

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    can a redirect be done through something like javascript?
    Can be, yes. Should be, no. Do it server-side. Most servers provide some configuration option that allows this sort of thing to be done. Check the documentation for yours.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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