send specific visitor (IP) a special page?

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
User avatar
wvoyance
Forum Contributor
Posts: 135
Joined: Tue Apr 17, 2012 8:24 pm

send specific visitor (IP) a special page?

Post by wvoyance »

I know I can block some specific IP by
order allow,deny
deny from 210.242.215.197/32
allow from all

But could I send them a specific page?
Those visitors are really nuscent I want to tell them do not come again. :roll:
User avatar
Celauran
Moderator
Posts: 6425
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: send specific visitor (IP) a special page?

Post by Celauran »

Why not use a PHP header redirect?

Code: Select all

header('Location: foo');
User avatar
wvoyance
Forum Contributor
Posts: 135
Joined: Tue Apr 17, 2012 8:24 pm

Re: send specific visitor (IP) a special page?

Post by wvoyance »

Celauran wrote:Why not use a PHP header redirect?

Code: Select all

header('Location: foo');
Then, they can still access other pages, to my understanding.
User avatar
Celauran
Moderator
Posts: 6425
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: send specific visitor (IP) a special page?

Post by Celauran »

Not necessarily. You can easily put the blacklist code in one of your included files or your front controller, depending on how your site is set up. In either scenario, every request will see this code called and the undesirables redirected away. Unless, of course, they come in through a proxy of some sort.
User avatar
wvoyance
Forum Contributor
Posts: 135
Joined: Tue Apr 17, 2012 8:24 pm

Re: send specific visitor (IP) a special page?

Post by wvoyance »

Celauran wrote:Why not use a PHP header redirect?

Code: Select all

header('Location: foo');
Could this command redirect only some visitor, not all?
I would like to redirect some visitor :P
User avatar
Celauran
Moderator
Posts: 6425
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: send specific visitor (IP) a special page?

Post by Celauran »

Well yes, of course. Wrap it in a conditional.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: send specific visitor (IP) a special page?

Post by VladSun »

Code: Select all

header('Location: foo');
exit(); // !!!!
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: send specific visitor (IP) a special page?

Post by pickle »

I believe you can do it in mod_rewrite & therefore in your .htaccess file like your original post:

[syntax]RewriteCond %{REMOTE_HOST} ^210\.242\.215\.197
RewriteRule .* /offline.php [R=302,L][/syntax]

I'm not entirely sure how to do it with IP ranges though
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Celauran
Moderator
Posts: 6425
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: send specific visitor (IP) a special page?

Post by Celauran »

The problem with using .htaccess is that you'd need a new entry for each IP or CIDR value versus being able to query a database if you do it in PHP.
User avatar
wvoyance
Forum Contributor
Posts: 135
Joined: Tue Apr 17, 2012 8:24 pm

Re: send specific visitor (IP) a special page?

Post by wvoyance »

Is every sub-directory which has an index.php need a .htaccess?

I put a .htaccess as the root directory but does not seems to be able to prevent access of some directories.
Put more .htaccess at those directories seems become o.k.
I found those directories seems all contain an index.php
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: send specific visitor (IP) a special page?

Post by pickle »

No, an .htaccess file is supposed to be applied to every subdirectory. I'm not sure if there are Apache directives that can be changed which make .htaccess only apply to the current directory, but I've always had them apply to ancestor directories.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply