Force visitors to go through index page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sillycheese
Forum Newbie
Posts: 3
Joined: Fri Feb 27, 2004 8:34 am
Location: philly, pa

Force visitors to go through index page?

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
sillycheese
Forum Newbie
Posts: 3
Joined: Fri Feb 27, 2004 8:34 am
Location: philly, pa

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post 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");
}
sillycheese
Forum Newbie
Posts: 3
Joined: Fri Feb 27, 2004 8:34 am
Location: philly, pa

Post 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.
User avatar
gangboy
Forum Newbie
Posts: 14
Joined: Tue Jan 06, 2004 11:58 am
Location: Constanţa, România

Post 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?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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
Post Reply