好的,我有一个会话类,当前处理设置变量,获取变量,删除它们并销毁它们。我有一个从用户获取信息的表单,我不知道如何使用会话类获取post变量,而不是仅使用$ _SESSION {'some variable']来设置变量并使用它们。
<?php
class sessionClass{
public function _constructor()
{
session_start();
}
public function destroy()
{
session_destroy();
}
public function add($name, $value)
{
if(empty($name)){
die('Invalid variable name');
}
$_SESSION[$name] = $value;
}
public function delete($name)
{
session_unset ($_SESSION[$name]);
}
public function get($name)
{
if(isset($_SESSION[$name]))
$_SESSION[$name] = $name;
else
return ($_SESSION[$name]);
}
}
?>
以上是我的会话课程。现在我正在尝试使用OOPHP,我正在尝试验证输入到我的模板表单页面的数据。但是因为我传递变量$ _POST ['LoginID']和$ _POST ['Password']我收到这些错误。
注意:未定义的索引:第20行/home/comp3170-020/public_html/assignment2/index.php中的LoginID注意:未定义的索引:/home/comp3170-020/public_html/assignment2/index.php中的LoginID在线25等等
//Creating class objects
$val = new validatorClass();
$ses = new sessionClass();
$dis = new XHTMLDisplayClass();
$dis->setTemplate('templates/index.tpl.php');
//Checking that data is validated
if (isset($_POST['Submit']))
{
if ((!$val->isValidLoginID($_POST['LoginID'])) || (!$val->isValidLoginIDE($_POST['LoginID'])) ||(!isValidPassword($_POST['Password'])))
{
$errs = $val->getErrorMessages();
$d-> addVar('errors', $errs);
}
else {
//$ses = new sessionClass();
$ses->add('LoginID', $_POST['LoginID']);
$ses->add('Password',$_POST['Password'] );
$ses->add('validationDone', true);
header('Location:auth.php');
exit;
}
}
任何人都可以告诉我应该如何将变量传递给类的函数。
表单代码:
<form name="form1" action="index.php" method="POST">
<td width="220" class="content_l">Login ID</td>
<font color = "FF0000">
<?php if (isset ($errors['isValidLoginID'])){echo $errors['isValidLoginID'];}?>
<?php if (isset ($errors['isValidLoginIDE'])){echo $errors['isValidLoginIDE'];}?>
<?php if (isset ($errors['isValidPassword'])){echo $errors['isValidPassword'];}?>
</font>
</tr>
<tr>
<td><input type="text" name="textfield" class="form250"></td>
</tr>
<tr>
<td height="25" valign="bottom" class="content_l">Password</td>
</tr>
<tr>
<td><input type="password" name="textfield" class="form250" ></td>
</tr>
<tr>
<tr>
<td height="25" valign="bottom" class="content_1">Identification Used</td>
</tr>
<tr>
<td><input type="radio" name="authtyp" value="Username" class="form250" <?php echo $usertyp?> checked>Username <input type="radio" name="authtyp" value= "Email" class="form250" <?php echo $emailtyp?>> Email</td>
</tr>
<tr>
<td height="40" valign="bottom">
<input type="submit" name="Submit" value="LOGIN" class="btn70" style="margin-top:10px; ">
</form>
</td>
</tr>
<tr>
<td height="30" valign="bottom"><a href="#" class="content_m" style="color:#333333">Forgot your password? </a></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>