By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,639 Members | 3,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,639 IT Pros & Developers. It's quick & easy.

how to direct users

P: 1
Can anyone tell me how to direct unregistered users who try to acess the inner pages back to the home page along with a error message telling them to please login to view the pages in PHP
Jan 27 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 4,258
You can accompish this by registering your logged-in users in a cookie or the session array and redirecting anyone who is not registered in there. The most basic approach to this is:

- start each of your scripts with the PHP session_start() command
when the user has logged in successfully, register his name in the $_SESSION array, e.g.
- at each page, check if the user is registered by checking the $_SESSION array, if not, redirect the user to the login script:
[php]if (!isset($_SESSION['username']))
header('Location: logon.php');
.. continue processing ..[/php]
A more complete and indepth tutorial on this subject can be found at The First Session.

Ronald :cool:
Jan 28 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.