...

View Full Version : Using my $_SESSION from one class on another



chrisiboy
10-09-2012, 06:23 PM
Hi Guys,

Below is my login class.



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.



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

Jimmaay
10-10-2012, 06:47 AM
You should use $output.=""; instead of $output = $output."".

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



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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum