Solved

losing session variables

Posted on 2006-06-08
6
373 Views
Last Modified: 2008-02-26
Please take a look at this script and see why I'm losing my sessions:

www.owndesigns.com/deed-david/admin/menuorder.txt
0
Comment
Question by:weikelbob
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
BobsRe earned 500 total points
ID: 16866972
Try not using numbers as the session key.  I have never heard of that before, but for som reason when I downloaded your cod on my server it worked when I changed the keys from numbers.  As a quick exampl change your $_SESSION['100']="TESTING123"; to $_SESSION['thf']="TESTING123";

If you need additional help let me know.
0
 
LVL 5

Expert Comment

by:BobsRe
ID: 16866986
Here I cleaned up the code a bit for you, but you need to readd your database stuff.  This is what I did to be able to troubleshoot, mostly just cleaning it up so I could read it.

<?php
session_cache_limiter('nocache');
session_cache_expire (40);
session_start();

error_reporting(E_ALL);
$errors=array();

if (isset($_POST['order2'])) {
      unset($_POST['submit']);
      foreach($_POST as $key => $value) {
            if(!is_numeric($value)) {
                  $errors[]="Your changes are not numeric";
            }
      }
      if(count($_POST) != count(array_unique($_POST))) {
            //there are some duplicates. Use a foreach to detect them.
            $errors[]="Your changes are invalid";
      }
      if (count($errors)==0) {
            // Array elements are NOT unique OR not integer - you can use $a_unique_ints to see all the unique ints available.
            if(isset($_POST['order2'])) {
                  for($j=1;$j<count($_POST) + 1;$j++) {
                        /* $a="order" . $j;
                        echo "a:" . $_POST[$a];
                        echo "<br><br>";
                        $query4="update deedtable set order1= '" . mysql_real_escape_string($_POST[$a]) . "' where order1= '" . mysql_real_escape_string($_SESSION[$j]) . "'";
                        $result4= mysql_query($query4); */
                  }
            }
      }
}

echo <<<END
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Admin Page</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="container">
   <div id="header">
      <img src="images/header1.jpg">
   </div>

   <div id="whitearea">
END;
print_r($_SESSION);
if (count($errors)>0) {
      $error = implode("<br />", $errors);
      $error = "<span style=\"color:red;font-weight:bold;\">" . $error . "</span>";
      echo $error;
}
echo "
   <p style='text-align:center'>
   To return to the admin home, click <a href='index.php'>here</a>.
   </p>
      <ul style='list-style-type:none'>
      <table cellpadding='1' cellspacing='1'>
      <form action='{$_SERVER['PHP_SELF']}' method='post'>
";

$i=0;
foreach (array(
                                 array("menu" => "Testqqq", "order1" => 1),
                                 array("menu" => "Testqqfdg", "order1" => 3),
                                 array("menu" => "dfgdg", "order1" => 5),
                                 array("menu" => "Tdfestdfg", "order1" => 6)
                                 ) as $row3) {
      echo "<tr>";
      echo "<td>";
      $i++;
echo <<<END
            <li>{$row3['menu']}
         </td>
         <td>  

       <input type="text" size="5" name="order<?php echo $i; ?>" value="{$row3['order1']}">
END;
       $_SESSION['DD' . $i] = $row3['order1'];
       $_SESSION['Thz'] = "TESTING123";      
            echo $_SESSION['DD' . $i];
echo "
            </li>
          </td>
          </tr>";
}

echo <<<END
     
<input type="submit" name="submit" value="Update a page's order">
       </form>
      </table>  
      </ul>
       <p style="text-align:center">
       click <a href="admin-new.php">here</a> to add a page.
       </p>
       
  </div>
<div id="clear1"></div>
</div>

</body>
</html>
END;
print_r($_SESSION);
?>
0
 
LVL 7

Author Comment

by:weikelbob
ID: 16873950
It's working!

so far....
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 5

Expert Comment

by:BobsRe
ID: 16873994
lol,  Good, glad I could help.

  Bobby
0
 
LVL 7

Author Comment

by:weikelbob
ID: 16874523
I didn't use your script, but I went back to my script and added an "a" in the sessions because you suggested to make them not only just numbers. Everything started working.

Thanks a lot.

Bob
0
 
LVL 5

Expert Comment

by:BobsRe
ID: 16874586
Ok I am glad it worked out.  Thanks for the points.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question