Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-09-2012, 05:23 PM   PM User | #1
chrisiboy
New to the CF scene

 
Join Date: Oct 2012
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
chrisiboy is an unknown quantity at this point
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
chrisiboy is offline   Reply With Quote
Old 10-10-2012, 05:47 AM   PM User | #2
Jimmaay
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Jimmaay is an unknown quantity at this point
$_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...}

Jimmaay is offline   Reply With Quote
Users who have thanked Jimmaay for this post:
chrisiboy (10-15-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:54 AM.


Advertisement
Log in to turn off these ads.