Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Forcing user to log in

I have created a login page (login.php) and a home page (index.html). The login page makes a query to the database and it seems to be working properly. However I want the user on the client side to only be able to reach the home page if (s)he has logged in. I could rename the login page to index.php and redirect the user from there, but that doesent stop anyone from just typing the absolute path to the home page. So what I want is whenever a user tries to reach the index.php site, to check if he or she is logged in, and if not redirect the user back to the login page.

1 Answer

This is exactly how to achieve this :D +rep

thanks a bunch =)