how to direct users

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shinyjoy
    New Member
    • Jan 2007
    • 1

    how to direct users

    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
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    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.
    [php]$_SESSION['username']=$user;[/php]
    - 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($_SESSI ON['username']))
    header('Locatio n: logon.php');
    else
    .. continue processing ..[/php]
    A more complete and indepth tutorial on this subject can be found at The First Session.

    Ronald :cool:

    Comment

    Working...