Connecting Tech Pros Worldwide Forums | Help | Site Map

restrict user access on certain pages

Member
 
Join Date: Mar 2007
Posts: 77
#1: Jun 30 '08
Hi PPL,

On my website i have setup user log in. once they log in i want to restrict certain users from certain pages.. and on some pages i want the user to enter their username and password again..but i am stuck on how to restrict them.. any user guides on how to tackle this issue..i am using dreamweaver cs3

many thanx

Newbie
 
Join Date: Jun 2008
Posts: 13
#2: Jun 30 '08

re: restrict user access on certain pages


I had this problem. I got over it by using 2 sessions (User and Admin). Each page that contains the session at the top checks to see what type of session the user is in and either allows, or header redirects to the index.

Another way could be to have a separate section. for example

yourdomain.com

and
yourdomain.com/admin

The admin index would be exactly the same, just rename the sessions. You can also use sql statements in the session code too, meaning you could add a column in your user table to include access rights maybe?

Heres an example of what i have used

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. include "conn.inc.php";
  4.  
  5. if (isset($_POST['submit'])) {
  6.   $query = "SELECT username, password FROM user_info " .
  7.            "WHERE username = '" . $_POST['username'] . "' " .
  8.            "AND password = (PASSWORD('" . $_POST['password'] . "'))";
  9.   $result = mysql_query($query) 
  10.     or die(mysql_error());
  11.  
  12.   if (mysql_num_rows($result) == 1) {
  13.     $_SESSION['user_logged'] = $_POST['username'];
  14.     $_SESSION['user_password'] = $_POST['password'];
  15.     header ("Refresh: 5; URL=" . $_POST['redirect'] . "");
  16.     echo "You are being redirected to your original page request!<br>";
  17.     echo "(If your browser doesn't support this, " .
  18.          "<a href=\"" . $_POST['redirect']. "\">click here</a>)";
  19.   } else {
  20. ?>
  21.  
  22.  
Reply