PDA

View Full Version : Autoclose if visitor comes via certain site?



RustyH
03-22-2007, 05:23 PM
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
:D

boxxertrumps
03-22-2007, 06:57 PM
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

Twey
03-22-2007, 07:18 PM
$_SERVER[HTTP_REFERER]Don't rely on the PHP parser to convert undefined constants to strings.
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 domainNo, 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.
<?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.

pcbrainbuster
03-22-2007, 07:36 PM
Use htaccess - i heard its possible i think :)

Twey
03-22-2007, 08:33 PM
Yes, a .htaccess file or equivalent would be a neater solution.

RustyH
03-23-2007, 11:48 AM
Thanks for the help guys, really appreciate it :D

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:
<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
:D

Twey
03-23-2007, 12:51 PM
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.