...

View Full Version : Strange Error is session variable



macleodjb
10-21-2009, 10:58 PM
Hi guys,

I'm having a strange error in my session vars. When the user logs in i set a few vars in my session array to be called at a later time.

For some reason when i call this file "leftcol.php" it rewrites my session variables to different things. I can't figure out why or where it's happening in this file. Any help is appreciated.

here's the file "leftcol.php".



<?php
$core = new Core_class();
echo "<div id='left_side'>\n";
if(isset($_SESSION['uid'])){

echo "<ul id='linklist'>\n";
$page = BASE_URL;
switch ($_SESSION['dept']) {
case "Engineering":
$page .= "main/dashboard.php";
break;
case "Cutlisting":
$page .= "main/cutlisting.php";
break;
case "Manufacturing":
$page .= "main/manufacturing.php";
break;
case "Project Management":
$page .= "main/pm.php";
break;
default:
$page .= "main/engineering.php?name=undef";
break;
}
echo "<li><a href='" .$page."'>Home</a></li>\n";
$q_all = "SELECT * FROM `nav_links` WHERE (`link_dept` = 'ALL')";
$all_links = $core->result_array($q_all);
foreach ($all_links as $all){
echo "<li><a href='". BASE_URL . $all['link_href'] ."'>" . $all['link_name'] ."</a></li>\n";
}
echo "</ul>\n";

if($_SESSION['eng'] > 1 ){
echo "<h3>Engineering</h3>";
echo "<ul id='linklist'>";
$q_eng1 = "SELECT * FROM `nav_links` WHERE (`link_dept` = 'ENGINEERING')";
$eng_links = $core->result_array($q_eng1);
foreach ($eng_links as $eng){
echo "<li><a href='".BASE_URL.$eng['link_href']."'>".$eng['link_name']."</a></li>\n";
}
echo "</ul>\n";
}

if($_SESSION['cut'] > 1){
echo "<h3>Cutlisting</h3>";
echo "<ul id='linklist'>";
$q_cut1 = "SELECT * FROM `nav_links` WHERE (`link_dept` = 'CUTLISTING')";
$cut_links = $core->result_array($q_cut1);
foreach ($cut_links as $cut){
echo "<li><a href='".BASE_URL.$cut['link_href']."'>".$cut['link_name']."</a></li>\n";
}
echo "</ul>\n";
}

if($_SESSION['manuf'] > 1){
echo "<h3>Manufacturing</h3>";
echo "<ul id='linklist'>";
$q_manuf1 = "SELECT * FROM `nav_links` WHERE (`link_dept` = 'MANUFACTURING')";
$manuf_links = $core->result_array($q_manuf1);
foreach ($manuf_links as $manuf){
echo "<li><a href='". BASE_URL . $manuf['link_href'] ."'>" . $manuf['link_name'] ."</a></li>\n";
}
echo "</ul>\n";
}

if($_SESSION['pm'] > 1){
echo "<h3>Project Management</h3>";
echo "<ul id='linklist'>";
$q_pm1 = "SELECT * FROM `nav_links` WHERE (`link_dept` = 'PROJECT_MANAGEMENT')";
$pm_links = $core->result_array($q_pm1);
foreach ($pm_links as $pm){
echo "<li><a href='". BASE_URL . $pm['link_href'] ."'>" . $pm['link_name'] ."</a></li>\n";
}
echo "</ul>\n";
}

if($_SESSION['admin'] == 1){
echo "<h3>Admin</h3>";
echo "<ul id='linklist'>";
$q_admin1 = "SELECT * FROM `nav_links` WHERE (`link_dept` = 'Admin')";
$admin_links = $core->result_array($q_admin1);
foreach ($admin_links as $admin){
echo "<li><a href='". BASE_URL . $admin['link_href'] ."'>" . $admin['link_name'] ."</a></li>\n";
}
echo "</ul>\n";
}


}?>
</div><!-- end of left column -->

tomws
10-22-2009, 12:30 AM
Am I overlooking your session_start() at the top of that file? Or is this included into a file with a session_start() already?

macleodjb
10-22-2009, 01:14 AM
yeah the session controls are done in my config.php include which is prior to this include. What i don't understand is that i already had this working on another server. All i did was copy all files and sql tables to another server and now it doesn't work properly.

I narrowed it down to the leftcol.php file. If i print out the session array before this include file it is correct, and after this include it is corrupted.

tomws
10-22-2009, 03:23 AM
Maybe a stupid test, but have you dumped the session var for testing at the top of this file? And at other locations throughout?

When you say the data is "corrupted" what do you mean? Junk data? Substrings? Letters? Numbers? Any pattern?

macleodjb
10-22-2009, 03:49 AM
yes i tried printing out the session array before this include file and its good. anywhere after this include the data is bad.

When i say corrupted i mean it's not as it should be. I found out what it is doing but i'm still clueless on how it's doing it.

If you print the session variable after this include file each session key such as eng, manuf, cut, and admin are repopulated with an array from navlinks. If you notice inside this include file there are several IF statements for each array key to display navigation links. If the user has privelages then it shows the nav links. So whats happening is that for each if statement for instance i have

IF($_SESSION['eng'] > 1){ do query }

its taking the last record from this query and assigning it to $_SESSION['eng']

so it does the same for each key so $_SESSION['manuf'] retrieves the last record from nav links and rewrites my session variable $_SESSION['manuf'] with an array of recordset.

It's totally weird because no where in this file do i assign values to the session.

tomws
10-22-2009, 04:15 AM
Actually, I was asking about putting the session var debugs within that file. Test it internally for weirdness since you suspect the problem is inside.

I just noticed that you're using variables within each of those if statements that match your session vars. For example, in the $_SESSION['eng'] test, you're using an $eng. Is register_globals on? You can check with a phpinfo() (http://us.php.net/phpinfo).

macleodjb
10-22-2009, 12:47 PM
you were right. Those variables were overwriting my session vars. i renamed them and they worked fine. Alternatively i could have turned off register globals. Thanks alot.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum