Page 1 of 1

Force visitors to go through index page?

Posted: Fri Feb 27, 2004 8:34 am
by sillycheese
What I want to do is force any visitor to go through my index.html page. If they happened to visit one of my subdomains, or browsed into a different directory, even though I set it up that way, I want them to be forced to go through the index.html page first. Let me explain this another way:

I have a directory in my htdocs folder called "chatroom", people can easily bookmark this and have direct access to this folder.

I want to "force" every visitor who tries to go to a subdirectory directly, to automatically be forced back to my main index.html page first, where they would find a menu to choose from where they want to go.

I guess this is kind of a anti-bookmark code in a way.

I already understand and use .htaccess file in my main directory under htdocs, and also have a .htpasswd file under the root, before htdocs.

If anyone understands what it is that I am asking, I would appreciate the help.

Oh yeah, if your gonna tell me it's not a good idea, or it might drive visitors away, blah blah blah. Dont waste your time. I need answers, not opinions.

Thanks.

Posted: Fri Feb 27, 2004 9:00 am
by JayBird
what about this at the top of all your pages

Code: Select all

$referrer = $_SERVER[HTTP_REFERER]."\n";
	
	
if ( !preg_match( "/your_domain_name/", $referrer ) ) {
		
	header("Location: index.php");
}
Mark

Posted: Fri Feb 27, 2004 9:08 am
by sillycheese
Thankyou for your idea, I shall certainly try it. At least I got an answer out of this forum and not yelled at ...lol

thanks.

Posted: Fri Feb 27, 2004 9:10 am
by JayBird
we only yell if you ask stupid questions :) . Yours was a legitimate question.

The code i gave is good for starter, only simple, you may need to expand on it for your particular purposes.

Mark

Posted: Fri Feb 27, 2004 9:11 am
by liljester
mmmm sessions.

have the index page set a session var

$_SESSION[index] = 1;


then check that session var on all the other pages, if the session var isnt set, redirect them

if($_SESSION[index] != 1){
header("Location: index.php");
}

Posted: Fri Feb 27, 2004 9:22 am
by sillycheese
Interesting ....

I will give it a shot. I imagine I would have to transform all of my html pages to php first though.

thankyou.

Posted: Fri Feb 27, 2004 10:20 am
by gangboy
sillycheese wrote:I would have to transform all of my html pages to php first though
Couldn't you just quote the code between <? //code// ?> tough?

Posted: Fri Feb 27, 2004 1:58 pm
by d3ad1ysp0rk
he means the extensions. so yes, you will. OR you could change it in your apache config file if you're running your own server..

and use <?php, not <?, don't be lazy :P