declaring session variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MatthewC
    New Member
    • Aug 2006
    • 1

    declaring session variables

    im a bit of a php n00b. I have this login script that works fine just trying ot add a session variable to get the data from the field usertype (this will be set as admin or user)

    ive tried the code below but getting parser errors the parts i have added that are not functioning are

    $usertype = $_POST['usertype'];

    $_SESSION['valid_type'] = get($usertype, "admin");

    Just want to know how to get this session to work correctly like the others do any help appreciated

    code below.

    <?
    include "functions/include_fns.php ";
    if (isset($_POST['username']) && isset($_POST['password'])) {

    $username = $_POST['username'];
    $password = $_POST['password'];
    $usertype = $_POST['usertype'];

    if (login($usernam e, $password, "admin")) {

    $sql

    $_SESSION['valid_user'] = $username;
    $_SESSION['valid_name'] = getname($userna me, "admin");
    $_SESSION['valid_type'] = get($usertype, "admin");

    if (isset($_POST['url']) && !empty($_POST['url'])) {
    $go_url = "".$url;
    header("Locatio n: $go_url");
    } else {
    header("Locatio n: home.php");
    }
    exit;
    } else {
    //status = 0: Incorrect Username or password
    //status = 1: Session has timed out or your are not logged in
    header("Locatio n: index.php?statu s=0");
    exit;
    }
    } else {
    header("Locatio n: index.php?statu s=0");
    exit;
    }
    ?>
  • Devendra
    New Member
    • Aug 2006
    • 12

    #2
    Hi friend i m not able to solve yr query but i m sending a file read care fully, if yr proble is not solved now send me full code on dpsingh07@gmail/rediffmail.com

    <?
    $varerror = '';
    $_SESSION['id'] = '';

    if(isset($_POST['submit']))
    {
    if( $_POST['name'] != '' && $_POST['password'] != '' )
    {
    $query=mysql_qu ery('select * from tbl_admin where user_name=\''.$ _POST['name'].'\' and
    user_password=\ ''.$_POST['password'].'\'');
    if(mysql_num_ro ws($query)>0)
    {
    while($rs = mysql_fetch_arr ay($query))
    {
    $_SESSION['id'] = $rs['admin_id'];
    header('locatio n:edit_user_pas sword.php');
    }
    }
    else
    {
    $varerror = 'Sorry username and password does not match. ';
    }
    }
    }
    ?>

    Comment

    Working...