我有一个在输入字段中显示用户当前帐号的配置文件页面。用户可以更改此帐号并提交表单以使用新帐号更新数据库。
我需要做的是获得初始帐号,以及新提交的帐号,以便我可以在同一页面上运行的另一个脚本中使用它们。
$user = Am_Di::getInstance()->auth->getUser();
$oldnum = $user->accountnumber;
$newnum = $_GET['accountnumber'];
$client2 = $api->findClient( mlApi::LICENSE_ACCOUNT, $oldnum );
$client = array( 'account_no' => $newnum, 'real_demo' => '1', 'comment' => 'test2' );
$api->updateClient( mlApi::LICENSE_ACCOUNT, $client2[_index], $client );
如果您想保存一个值以供将来使用,有两种常见的方法(可能是其他方法)来处理它。
- 保存在会话
- 在用户表单中作为隐藏的表单元素呈现,并从客户端读取它。
后者有100%的安全问题,因为恶意用户可以在下一个请求到来之前更改此id。为了演示
<input type='hidden' name='account_id' value='<?php echo $account?>' />
<input type='text' name='account_id_text' value='<?php echo $account?>' />
这种方法的使用是非常不鼓励的。
第一种方法,使用会话是所有机制中最安全的。
利用
$_SESSION['account_id'] = $account_id;
//render the view here
我希望这能回答你的问题