【发布时间】:2015-06-18 15:34:33
【问题描述】:
我遇到了关于 PHP 会话的问题。此代码应显示感谢您注册以及相应的用户名和电子邮件 ID,但它没有显示任何内容!请帮帮我!
<?php
//initialize session data
session_start();
if(isset($_SERVER['username'])){
echo "you are already logged in as: ".$_SERVER['username'];
}
elseif($_SERVER['REQUEST_METHOD' == 'POST']){
if(!empty(trim($_POST['username'])) && !empty(trim($_POST['email']))){
$uname = $_POST['username'];
$email = $_POST['email'];
echo "thanks for registering <br/>";
echo "your username: $uname <br/>";
echo "your email: $email <br/>";
}
else{
echo "please fill both the fields properly";
}
}
else{ ?>
<form action="index.html?username=overwritten" method="POST">
<input type="text" placeholder="username here.." name="username"><br/>
<input type="email" placeholder="email here.." name="email"><br/>
<input type="submit" value="register">
</form>
<?php }
?>
它还显示: 注意:未定义的偏移量:第 7 行 /Applications/XAMPP/xamppfiles/htdocs/samiary.com/index.php 中的 0 在顶端 请帮帮我,我只是一个初学者。
【问题讨论】:
-
我想你需要
$_SERVER['username']而不是$_SESSION['username']