Dynadot Black Friday and Cyber Monday 2026: save more on domains. See our sales.

Restricting Access With .htaccess

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Watch

TWM

Web Marketing SpecialistEstablished Member
Impact
9
How would i go about only letting people have access to a certain area when they arive there from a certain place?

EX:

I have a members only area. You login by filling out a simple script, and its processed in login.php. When you login it directs you to another url... mywebsite.com/membersarea. Nothing is secure, so you could just go to that URL without logging in...noone knows that, but they could figure it out.

I want to use .htaccess so that the only way you can view that directory is if you come FROM mywebsite.com/login.php. Can this be done?
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
0
Close
Not really what i need... i basically need it to do this:

If a user comes from a certain file, give access. If it comes from ANY other place, restrict access.
 
0
Close
Using the REFERER of the browser is insecure, people can set the REFERER field, and it's not reliable.

You can do other options, such as within the login script, after a successful login, insert their IP address and username in a "current_connections" table. Pass the username to the members area page when you redirect and very first thing in the members area page verify that the connection for the username is coming from the same IP (hence, they went through the login page successfully). Of course, you'd have to remove them from the "current_connections" table either when they manually log out of the system, and have a method of removing "stale" logins from the system as well...

Then, if they bypass the login script and go right to the members page and they haven't gone through the login script, the members page will see their username/IP pair isn't in the current_connections table and you can redir them back to the login page.

And this keeps it all server-side, which avoids the pitfalls of using cookies...

hmm... that took more time to explain that it would have to just write.. lol..
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

New: watch any domain
You can now watch domains on NamePros. We check each one and notify you when something changes. Search for a domain and press Watch on...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back