Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Using my $_SESSION from one class on another

    Hi Guys,

    Below is my login class.

    PHP Code:
    public function Login($username$password)
        {
            
    $cmd "select 
                        airtime_user_id, 
                        passwd_change_flag, 
                        mod_download_cdr, 
                        mod_download_sim_summary, 
                        mod_user_add, 
                        mod_user_permissions,
                        mod_custom_reports,
                        logo_file,
                                            mod_interactive_report,
                                            is_admin,
                                            mod_admin_tools
                    FROM airtime_users
                    where username = '" 
    $this->CheckInjection($username) . "' and passwd = '" md5($password) . "'";
                    
                    
            if(!
    $result $this->db->RetrieveCommandExec($cmd))
            {
                echo(
    $this->db->GetError());
                return 
    false;
            }
            else
            {
                
    session_start();
                
                
    $_SESSION['auth']['user'] =  $this->CheckInjection($username);
                
    $_SESSION['auth']['user-id'] = $result[0]['airtime_user_id'];
                
    $_SESSION['auth']['passwd-change'] = $result[0]['passwd_change_flag'];
                
    $_SESSION['auth']['mod-download-cdr'] = $result[0]['mod_download_cdr'];
                
    $_SESSION['auth']['mod-download-sim-summary'] = $result[0]['mod_download_sim_summary'];
                
    $_SESSION['auth']['mod-user-add'] = $result[0]['mod_user_add'];
                
    $_SESSION['auth']['mod-user-permissions'] = $result[0]['mod_user_permissions'];
                
    $_SESSION['auth']['mod-custom-reports'] = $result[0]['mod_custom_reports'];
                            
    $_SESSION['auth']['mod-interactive-reports'] = $result[0]['mod_interactive_report'];
                            
    $_SESSION['auth']['is-admin'] = $result[0]['is_admin'];
                            
    $_SESSION['auth']['mod-support-tools'] = $result[0]['mod_admin_tools'];
                            
    $_SESSION['auth']['logo-file'] = $result[0]['logo_file'];
                return 
    true;
            }
            
            return 
    false;
        } 
    Basically I want to output or hide my output according to the sessions above in a different class as below.

    PHP Code:
    private function getUserEditForm(AirtimeUser $user)
        {   
            
            
            
    $output "<form name=\"main\" method=\"post\">";
            
    $output $output "<table width=100%>";
            
    $output $output "<tr><td>User Id</td><td>" $user->get_airtime_user_id () . "</td></tr>";
            
            
    $output $output "<tr><td>CDR Download permission</td><td><input type=text name=mod_download_cdr  value=" $user->get_mod_download_cdr () . "></td></tr>";
            
    $output $output "<tr><td>SIM Summary download permission</td><td><input type=text name=mod_download_sim_summary  value=" $user->get_mod_download_sim_summary () . "></td></tr>";
            
    $output $output "<tr><td>Allow user management</td><td><input type=text name=mod_user_add  value=" $user->get_mod_user_add () . "></td></tr>";
            
            
    $output $output "<tr><td>Allow permission management</td><td><input type=text name=mod_user_permissions  value=" $user->get_mod_user_permissions () . "></td></tr>";
            
            
    $output $output "<tr><td>Allow access to custom reports</td><td><input type=text name=mod_custom_reports  value=" $user->get_mod_custom_reports () . "></td></tr>";
            
    $output $output "<tr><td>Allow access to interactive reports</td><td><input type=text name=mod_interactive_report  value=" $user->get_mod_interactive_report () . "></td></tr>";
            
    $output $output "<tr><td>Username</td><td><input type=text name=username  value=" $user->get_username () . "></td></tr>";
            
    $output $output "<tr><td>Password</td><td><input type=password name=passwd  value=" $user->get_passwd () . "></td></tr>";
            
    $output $output "<tr><td>Parent User</td><td><input type=text name=parent_user_id value=" $user->get_parent_user_id() . "></td></tr>";
            
    $output $output "<tr><td colspan=2><a href=\"javascript:saveUser(" $user->get_airtime_user_id () . ");\">Save User</a>";
            
            if(!
    $user->isNewUser())
            {
                
    $output $output " :: <a href=\"javascript:setSimPermissions(" $user->get_airtime_user_id () . ");\">Modify SIM permissions</a>";
                
    $output $output " :: <a href=\"javascript:setReportPermissions(" $user->get_airtime_user_id () . ");\">Modify Report permissions</a>";
            }
            
            
    $output $output "</td></tr>";
            
    $output $output "</table></form>";
            
            return 
    $output;
        } 
    So what I want to do :

    if $_SESSION['auth']['mod-download-cdr'] = 1
    then
    $output = $output . "<tr><td>CDR Download permission</td><td><input type=text name=mod_download_cdr value=" . $user->get_mod_download_cdr () . "></td></tr>";
    else don't post anyhting

  • #2
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    $_SESSION is a superglobal

    You should use $output.=""; instead of $output = $output."".

    $_SESSION is a superglobal so all your class methods can access it.

    PHP Code:
    private function getUserEditForm(AirtimeUser $user) {    
        if (
    $_SESSION['auth']['mod-download-cdr'] = 1){code...}


  • Users who have thanked Jimmaay for this post:

    chrisiboy (10-15-2012)


  •  

    Posting Permissions

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