Hi Guys! I've a problem here with the $_SESSION coding. As u can see from the coding below, I've declared several session after a user is log in. I want to display the $_SESSION['SESS_ADMIN_LEVEL'] in adLandingpage.php but the code is not work.

logincode.php

     $resultA = mysql_query("SELECT * FROM staff WHERE staff_id='$myid' AND level='ADMIN' AND password='$mypassword' and enabled='ACTIVE'" );
     $result16 = mysql_query("SELECT * FROM staff" );
     $count3 = mysql_num_rows($resultA);
      $row1 = mysql_fetch_array($resultA);

                    if($count3==1){ 

                    session_regenerate_id(); 
                       $admin = mysql_fetch_assoc($result16);   
                       $_SESSION['SESS_ADMIN_ID'] = $admin['staff_id']; 
                       $_SESSION['SESS_ADMIN_NAME'] = $admin['name'];
                       $_SESSION['SESS_ADMIN_LEVEL'] = $admin['level'];
                        session_write_close(); 

                    header('Location:adLandingPage.php');

                    $insertSQL = "INSERT INTO login_table (staf_id,time) VALUES ('$myid',NOW())";
                    $Result1 = mysql_query($insertSQL) or die(mysql_error());

                            }
                            //} 


//if ($_POST['user']='S'){

            $result = mysql_query("SELECT * FROM staff WHERE staff_id='$myid' AND level='STAFF' AND password='$mypassword' and enabled='ACTIVE'" );
            $result6 = mysql_query("SELECT * FROM staff " );
            $count=mysql_num_rows($result);


                    if($count==1){ 
                    session_start();
                    session_regenerate_id(); 
                       $staff = mysql_fetch_assoc($result6);   
                       $_SESSION['SESS_STAFF_ID'] = $staff['staff_id']; 
                       $_SESSION['SESS_STAFF_NAME'] = $staff['name'];
                       $_SESSION['SESS_STAFF_LEVEL'] = $staff['level'];
                        session_write_close(); 

                    header('Location:LandingPage.php');

                    $insertSQL = "INSERT INTO login_table (staf_id,time) VALUES ('$myid',NOW())";
                    //mysql_select_db($db_name);
                    $Result1 = mysql_query($insertSQL) or die(mysql_error());

                    }

i want to display the session result here.This is for admin page. It should display Logged in as:ADMIN but the result is Logged in as:STAFF.Anyone..Please help?

adLandingpage.php

 <br clear="all"/>
                <hr />
                <div align="right" class="Arial12"><font color="#666666">Logged in As:<?php echo $_SESSION['SESS_ADMIN_LEVEL'];?></font></div>
                <br/>
                    <table width="200" border="0" cellpadding="10" cellspacing="0" class="Arial12" style=" margin: 0px auto;"  >

Recommended Answers

All 3 Replies

You should keep only one variable lik
SESS_LEVEL user that everywhere, do not user separate variables.

after header function always write exit, to avoid further execution of page

header("xy.php");
exit;

Before you use any sessions, or before a session can work for you; you first have to start the session using the session_start function.You will need to start the session first by declaring it at the beginning of the page;

<?php
session_start();

// Your $_SESSION variables will then go here
?>

okay,thanks guys!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.