我从来没有真正使用过会话,所以这可能是一些愚蠢的错误。当我使用 if(isset($_SESSION) 它输出 false 时,我认为它与 foreach 有关。我没有任何错误。任何人都可以抽出一些时间来帮助我吗?
<?php
session_start();
if(isset($_POST['register']))
{
require_once('../resources/library/register.class.php');
//require_once('../resources/library/sessions.class.php');
$obj_reg = new register();
$name = $_POST['user'];
$pass = $_POST['pass'];
$email = $_POST['email'];
$checking = $obj_reg->checking($name, $pass);
//An foreach for converting POST data inside SESSION variables
//isset checks if the array value contain post variables
$posts = array($name, $pass, $email);
foreach ($posts as $p)
{
if(isset($_POST['p'])){
$_SESSION['p'] = $_POST['p'];
}
}
}
?>
<form method="post" action="index.php?page=register.php">
<table>
<tr><td>username:</td><td> <input type="text" name="user"></td></tr>
<tr><td>password:</td><td> <input type="password" name="pass"/></td></tr>
<tr><td>email:</td><td> <input type="text" name="email"/></td></tr>
<?=( !empty( $checking ) ) ? $checking : '' ?>
</table>
<input type="hidden" name="token" value="<?=$token;?>"/>
<input type="submit" name="register" value="register"/>
</form>
<?php
session_start();
if(isset($_SESSION['p']))
{
echo "mama";
}
else
{
echo "why?";
}
?>