SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast dropper's Avatar
    Join Date
    Jan 2006
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question help on loading a particular page please

    hello!
    i'm a newbie to php. this codes were generated from dreamweaver as my php editor. i wanted to load into different pages and i understand that this codes only loads either from 2 pages, that is to adminpage.php if succesfully logged in and back to index.php if not. using the if statement, how will i modify the codes inorder that if a plain user logs in, it will be redirected to userpage.php.
    thanks guys!

    login table:
    userid | username | password
    -----------------------------
    1 | admin | adminpass
    2 | user1 | user1pass
    -----------------------------
    and the rest of users are also plain users.

    index.php

    PHP Code:
    <?php require_once('Connections/conn_mydb.php'); ?>
    <?php
    // *** Validate request to login to this site.
    if (!isset($_SESSION)) {
      
    session_start();
    }

    $loginFormAction $_SERVER['PHP_SELF'];
    if (isset(
    $_GET['accesscheck'])) {
      
    $_SESSION['PrevUrl'] = $_GET['accesscheck'];
    }

    if (isset(
    $_POST['username'])) {
      
    $loginUsername=$_POST['username'];
      
    $password=$_POST['password'];
      
    $MM_fldUserAuthorization "";
      
    $MM_redirectLoginSuccess "adminpage.php";
      
    $MM_redirectLoginFailed "index.php";
      
    $MM_redirecttoReferrer false;
      
    mysql_select_db($database_conn_mydb$conn_mydb);
      
      
    $LoginRS__query=sprintf("SELECT userName, userPassword FROM logintb WHERE userName='%s' AND userPassword='%s'",
        
    get_magic_quotes_gpc() ? $loginUsername addslashes($loginUsername), get_magic_quotes_gpc() ? $password addslashes($password)); 
       
      
    $LoginRS mysql_query($LoginRS__query$conn_mydb) or die(mysql_error());
      
    $loginFoundUser mysql_num_rows($LoginRS);
      if (
    $loginFoundUser) {
         
    $loginStrGroup "";
        
        
    //declare two session variables and assign them
        
    $_SESSION['MM_Username'] = $loginUsername;
        
    $_SESSION['MM_UserGroup'] = $loginStrGroup;          

        if (isset(
    $_SESSION['PrevUrl']) && false) {
          
    $MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
        }
        
    header("Location: " $MM_redirectLoginSuccess );
      }
      else {
        
    header("Location: "$MM_redirectLoginFailed );
      }
    }
    ?>
    Last edited by dropper; Mar 10, 2006 at 07:06.

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Enthusiast dropper's Avatar
    Join Date
    Jan 2006
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 7stud
    sorry... and thanks for the reminders

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, you could just check to see if the username is admin, if so redirect them to the adminpage, else redirect to userpage

    but all thats going to do is send thier browser to a starting page, its not going to prevent them from going to the adminpage.php by typing in the url.

    on adminpage.php, and any other admin only pages, you could add a check to see what thier username is, and that would keep regular users from using those pages.

    i never used dreamweaver for php code, but looking at what you posted it looks like dreamweaver supports different usergroups for its login system.

    i would consult the documentation to see how to do that.


    if you just want a quick fix...
    change this
    PHP Code:
    header("Location: " $MM_redirectLoginSuccess ); 
    to this
    PHP Code:
    if ($loginUsername == 'admin') {
        
    header("Location: " $MM_redirectLoginSuccess );
    } else {
        
    header("Location: userpage.php");


    and then at the top of your adminpage.php add this below session_start();

    PHP Code:
    if ($_SESSION['MM_Username'] != 'admin') {
        die(
    'admin only page');


    btw- if your trying to learn php, id recomend learning how to code it by hand. maybe some people will disagree, but i think ide's like dreamweaver are bad for learning.

  5. #5
    SitePoint Enthusiast dropper's Avatar
    Join Date
    Jan 2006
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by clamcrusher
    btw- if your trying to learn php, id recomend learning how to code it by hand. maybe some people will disagree, but i think ide's like dreamweaver are bad for learning.
    Thanks a lot for the great help clamcrusher!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •