interface + sessions = not working
Posted: Tue Feb 28, 2006 3:40 pm
feyd | Please use
pls help this is my first go and sessions and everything seems right... what am I doing wrong?
EDIT ++
I think I may have spoted it... I think since I have it retrieving a $_POST and plugging values its somehow overwriting with blanks since no info is being posted...
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
I am trying to make a simple interface feature that will allow the user to pick the product information they would like to see, or allow us to select the most important information for the user to see on the fly via an updateable var.
I figured a good way to do this was simple sessions, I have used cookies in the past but never sessions so I have a basic idea of how this should work.
Okay now to the issue.
if its your first time looking at the page, it defaults all viewable, next if the user unchecks and updates it hides the information they didn't leave checked. This works great, the reset check box also works fine... untill I jump to a page, even if its the same page...... if I refresh it remains working, its only when I click a link does it lose all of the interface settings. I assumed I was somehow losing the sessID but if you look at the bottom you will see it doesn't change, it remains the same, but all the $_SESSION values for some reason don't get passed or processed.
what am I doing wrong?
example of file doing its business : http://boom.clanned.net/sess/Code: Select all
<?PHP
session_start();
$resetView = $_POST['resetView'];
if ($resetView == "on"){
unset($_SESSION['firstRun']);
}
if (isset($_SESSION['firstRun'])){
// PULL CHECKED STATES
$field1 = $_POST['field1'];
$field2 = $_POST['field2'];
$field3 = $_POST['field3'];
$field4 = $_POST['field4'];
$field5 = $_POST['field5'];
$field6 = $_POST['field6'];
$field7 = $_POST['field7'];
$field8 = $_POST['field8'];
// FILL BLANKS RETURNED FROM FORM
if ($field1 != "on") {
$field1 = "off";
}
if ($field2 != "on") {
$field2 = "off";
}
if ($field3 != "on") {
$field3 = "off";
}
if ($field4 != "on") {
$field4 = "off";
}
if ($field5 != "on") {
$field5 = "off";
}
if ($field6 != "on") {
$field6 = "off";
}
if ($field7 != "on") {
$field7 = "off";
}
if ($field8 != "on") {
$field8 = "off";
}
//WRITE NEW SESSION VARIABLES
$_SESSION['field1'] = $field1;
$_SESSION['field2'] = $field2;
$_SESSION['field3'] = $field3;
$_SESSION['field4'] = $field4;
$_SESSION['field5'] = $field5;
$_SESSION['field6'] = $field6;
$_SESSION['field7'] = $field7;
$_SESSION['field8'] = $field8;
} else {
$_SESSION['firstRun'] = "1";
$_SESSION['field1'] = "on";
$_SESSION['field2'] = "on";
$_SESSION['field3'] = "on";
$_SESSION['field4'] = "on";
$_SESSION['field5'] = "on";
$_SESSION['field6'] = "on";
$_SESSION['field7'] = "on";
$_SESSION['field8'] = "on";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style>
DIV {
border:1px solid #cccccc;
padding:10px;
margin:2px;
}
FORM {
padding:10px;
background-color:#CCCCCC;
}
.display TD {
text-align:center;
}
</style>
</head>
<body>
<div id="options">
<form action="index.php" method="post">
<b>Customer View Customization</b><hr />
<table width="100%" border="0" cellspacing="0">
<tr>
<td>name:<input type="checkbox" name="field1" <?PHP if($_SESSION['field1'] == "on") echo "checked=\"checked\""; ?> />
</td>
<td>sku:<input type="checkbox" name="field2" <?PHP if($_SESSION['field2'] == "on") echo "checked=\"checked\""; ?> />
</td>
</tr>
<tr>
<td>height:<input type="checkbox" name="field3" <?PHP if($_SESSION['field3'] == "on") echo "checked=\"checked\""; ?> />
</td>
<td>width:<input type="checkbox" name="field4" <?PHP if($_SESSION['field4'] == "on") echo "checked=\"checked\""; ?> />
</td>
</tr>
<tr>
<td>weight:<input type="checkbox" name="field5" <?PHP if($_SESSION['field5'] == "on") echo "checked=\"checked\""; ?>/>
</td>
<td>cage code:<input type="checkbox" name="field6" <?PHP if($_SESSION['field6'] == "on") echo "checked=\"checked\""; ?>/>
</td>
</tr>
<tr>
<td>something:<input type="checkbox" name="field7" <?PHP if($_SESSION['field7'] == "on") echo "checked=\"checked\""; ?>/>
</td>
<td>webbles:<input type="checkbox" name="field8" <?PHP if($_SESSION['field8'] == "on") echo "checked=\"checked\""; ?>/></td>
</tr>
<tr>
<td> </td>
<td></td>
</tr>
</table>
<input type="submit" value="update view" /><br />
reset view: <input type="checkbox" name="resetView"/> (this will reset your view settings to defaults)
</form>
</div>
<table width="100%" class="display">
<tr>
<?PHP
if ($_SESSION['field1'] == "on"){
echo "<td><div>name</div></td>";
}
?>
<?PHP
if ($_SESSION['field2'] == "on"){
echo "<td><div>sku</div></td>";
}
?>
<?PHP
if ($_SESSION['field3'] == "on"){
echo "<td><div>height</div></td>";
}
?>
<?PHP
if ($_SESSION['field4'] == "on"){
echo "<td><div>width</div></td>";
}
?>
<?PHP
if ($_SESSION['field5'] == "on"){
echo "<td><div>weight</div></td>";
}
?>
<?PHP
if ($_SESSION['field6'] == "on"){
echo "<td><div>cage code</div></td>";
}
?>
<?PHP
if ($_SESSION['field7'] == "on"){
echo "<td><div>something</div></td>";
}
?>
<?PHP
if ($_SESSION['field8'] == "on"){
echo "<td><div>webble wobbles never fall down</div></td>";
}
?>
</tr>
</table>
<a href="index.php">go to other page
</a>
<p>
<?PHP
echo ("Session ID = ".session_id());
?>
</p>
</body>
</html>EDIT ++
I think I may have spoted it... I think since I have it retrieving a $_POST and plugging values its somehow overwriting with blanks since no info is being posted...
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]