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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts

    Strange Error is session variable

    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 Code:
    <?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'] > ){
        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 -->

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Am I overlooking your session_start() at the top of that file? Or is this included into a file with a session_start() already?
    Are you a Help Vampire?

  • #3
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    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.

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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?
    Are you a Help Vampire?

  • #5
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    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.

  • #6
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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().
    Are you a Help Vampire?

  • Users who have thanked tomws for this post:

    macleodjb (10-22-2009)

  • #7
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    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.


  •  

    Posting Permissions

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