Log in

View Full Version : Force redirect



glucarelli
06-21-2006, 11:03 AM
Hello all :)

On my website there is many pages,for images(http://mywebsite/image/index.html), forum
(http://mywebsite/forum/index.php).I would like to force visitors to come from
my homepage (http://mywebsite/index.html) even if they bookmarked the link of my image and forum index (because the complete link appear in message and status bar).
How could i do it :confused:

Any advice would be helpfull :cool:

djr33
06-21-2006, 11:48 PM
For security, you'd want to use php. I don't even know if you can use javascript for this.

Anyway, it's something like this:

<?php
if ($_SERVER[HTTP_REFERER] != "http://yourwebpage.com/page.htm") {
die('<meta http-equiv="redirect" content="0;url="http://your.com/page.htm">');
}

Notes:
-I don't thnk that the server variables need '' around them.... might be 'HTTP_REFERER', but I don't think so. Check that if you get an error.
-Using a header redirect would be a bit better, but I'm not sure on the code for those. Look them up if you want.


This work?

glucarelli
06-22-2006, 02:12 PM
Thanks for the answer

I didn't understand the difference beetwen http://yourwebpage.com/page.htm and http://your.com/page.htm so i can't try this solution.
I understand that:
http://yourwebpage.com/page.htm = http://mywebsite/index.html and
http://your.com/page.htm = http://mywebsite/image/index.html or http://mywebsite/forum/index.php
Is it correct ?
And do i have to put this code anywhere in index.php of forum page ?

Thank you for your answer.

Twey
06-22-2006, 02:31 PM
(sigh)

<?php
if ($_SERVER['HTTP_REFERER'] !== "http://yourwebpage.com/page.htm")
header("Location: http://your.com/page.htm");
?>djr33, your code standard's really slipping.

I didn't understand the difference beetwen http://yourwebpage.com/page.htm and http://your.com/page.htm so i can't try this solution.yourwebpage.com/page.htm is the homepage. your.com/page.htm is the page you wish to redirect from.

This is unwise, since some firewalls strip the Referer header.

glucarelli
06-22-2006, 03:27 PM
Thanks for your answer Twey

Doesn't work

My homepage is http:/onlinehome.fr/index.html
There is a link inside pointing to http:/onlinehome.fr/calendrier/calendar.php
I don't want user accessing this page directly they have to go to homepage first.So according to your solution i have modified calendar.php inside <head> tag like this:
<?php
if ($_SERVER['HTTP_REFERER'] !== "http://onlinehome.fr/index.html")
header("Location: http:/onlinehome.fr/calendrier/calendar.php");
?>

What's wrong ?

djr33
06-22-2006, 08:41 PM
This is unwise, since some firewalls strip the Referer header.
Ah, that would be a problem, then.

I suppose you could try something more complex to track where their last page was... cookies, database, etc.

Maybe try a cookie on the homepage, and if that cookie doesn't exist, then redirect there. If they've already been to the homepage and later go right to the secondary page, that's ok, right?

Twey
06-22-2006, 10:22 PM
There should be two slashes after the protocol.
djr33: What about browsers without cookies enabled?

djr33
06-22-2006, 10:29 PM
True.

In the end, the question is whether this is such an important thing that you would rather lose some visitors than have them see it in order to make people need to come from a certain page.

You could do both ways, and just hope that most people have one or the other. Still wouldn't be everyone, though.