You are here: Re: why a session-based program behaves different on different computers « PHP Programming Language « IT news, forums, messages
Re: why a session-based program behaves different on different computers

Posted by davidkoree on 04/19/07 07:07

Thank you steve.

Generally the program has 5 steps, and the first 4 steps need user to
input some data, and the last one outputs the result. Every user must
starts with the 1st step, if not, the program will give user a message
like 'You should starts with the 1st step' or 'You could continue on
the n step'.

I use session to keeping user's inputs and status of steps. When user
finish he/she can go back to edit his/her inputs, but some computers
show that when user go back to check, the program give a random
message like 'You could continue on the n step'. It should not be
shown because the whole status have been set to 'done' in session
variable. like:

Array ( [step1_1] => done [step1_2] => done [step1_3] => done [step2]
=> done [step3] => done [step4] => done )

The core codes of the program:

<?php
class F5S {
//current working page
public $_filename;
//status
public $_status = array();
//data
public $_data = array();
//dictionaries
public $_dict_page2step = array("b_lcwb_1b.php"=>"step1_",
"b_lcwb_1c.php"=>"step1_", "b_lcwb_2.php"=>"step1_",
"b_lcwb_3.php"=>"step2_", "b_lcwb_4.php"=>"step3_",
"b_lcwb_5.php"=>"step4_");
public $_dict_page2status = array("b_lcwb_1b.php"=>"step1_1",
"b_lcwb_1c.php"=>"step1_2", "b_lcwb_2.php"=>"step1_3",
"b_lcwb_3.php"=>"step2", "b_lcwb_4.php"=>"step3",
"b_lcwb_5.php"=>"step4");
public $_dict_status2nextstep = array("step1_1"=>"Step 1,
2 ...","step1_2"=>"Step 1, 3 ...","step1_3"=>"Step
Two ...","step2"=>"Step 3 ...","step3"=>"Step 4 ...","step4"=>"Step
5 ...");

/**
* set current working page
*
* @param string $path
* @return string
*/
function setFileName($path) {
$pathinfo = pathinfo($path);
$this->_filename = $pathinfo["basename"];
}

/**
* move to the next step that needs to be finished
*
* @param string $nextstep
* @param string $filename
*/
function removeToStep($nextstep, $pagename) {
$format = "<script language='javascript' type='text/
javascript'>alert('You could continue on the
%s.');location.href='%s';</script>";
echo sprintf($format, $nextstep, $pagename);
}

/**
* route steps workflow
*
*/
function routeWorkflow() {
if (count($this->_status) > 0) {
$dict_status2page = array_flip($this->_dict_page2status);
$nextstep = $this->_dict_status2nextstep[array_pop(array_flip($this-
>_status))];
$pagename = $dict_status2page[array_pop(array_flip($this-
>_status))];
$this->removeToStep($nextstep, $pagename);
} else {
echo "<script language='javascript' type='text/
javascript'>alert('You should starts with the 1st
step.');location.href='b_lcwb_1a.php';</script>";
}
}

/**
* check steps workflow
*
* @param string $path
* @return boolean
*/
function checkWorkflow() {
$filename = $this->_filename;
if (in_array($this->_dict_page2status[$filename], array_keys($this-
>_status))) {
return true;
} else {
return false;
}
}

/**
* collect user inputs
*
* @param filename $path
* @param array $postvar
*/
function collectData($postvar) {
$filename = $this->_filename;
foreach (array_keys($postvar) as $name) {
$this->_data[$this->_dict_page2step[$filename].$name] =
$postvar[$name];
}
}

/**
* update status of steps
*
* @param string $path
*/
function updateStatus() {
$filename = $this->_filename;
$this->_status[$this->_dict_page2status[$filename]] = "done";
}
}
?>

And step page:

<?php
require_once("F5S.php");
session_start();
print_r($_SESSION["f5s"]->_status);
if (isset($_SESSION["f5s"])) {
$_SESSION["f5s"]->setFileName(__FILE__);
if (count($_POST) > 0) {
$_SESSION["f5s"]->collectData($_POST);
$_SESSION["f5s"]->updateStatus();
$_SESSION["f5s_data"] = $_SESSION["f5s"]->_data;
$_SESSION["f5s_status"] = $_SESSION["f5s"]->_status;
} elseif ($_SESSION["f5s"]->checkWorkflow()) {
$_SESSION["f5s_data"] = $_SESSION["f5s"]->_data;
$_SESSION["f5s_status"] = $_SESSION["f5s"]->_status;
} else {
$_SESSION["f5s"]->routeWorkflow();
}
} else {
$_SESSION["f5s"] = new F5S();
$_SESSION["f5s"]->setFileName(__FILE__);
$_SESSION["f5s"]->routeWorkflow();
}
?>

Strangely some computers run the program correctly (with IE6/FF2/
Maxthon) but others don't. I need help, really~

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация