如何在
用户登录时隐藏授权表单?相反,我希望用户看到:Welcome, %username%
。
到目前为止我的代码
<?if(!isset($_SESSION['id'])):?>
<form action="testreg.php" method="post" }>
<p>
<label><span">Username:</span></span><br>
</label>
<input name="login" type="text" size="25" maxlength="15">
</p>
<p>
<label><span class="style3">Password:</span><br>
</labe l>
<input name="password" type="password" class="style3" size="13"
maxlength="15">
</p>
<p><input name="submit" type="submit" value="Enter">
<a href="reg.php" class="style4">Need an account?</</a></p>
</form>
<?php
if (empty($_SESSION['login']) or empty($_SESSION['id']))
{
echo "You have signed in<br><a href='#'>Available only for you</a>";
}
else
{
echo "Welcome, ".$_SESSION['login']."<br><a href='link'>Profile</a>";
}
?>
<?endif?>
给你的表单一个像这样的ID
<form id="loginForm" action="testreg.php" method="post">
在欢迎用户的PHP中,加入一些内联样式。
if (empty($_SESSION['login']) or empty($_SESSION['id']))
{
echo "You have signed in<br><a href='#'>Available only for you</a>";
}
else
{
echo ' //Add this bit here
<style>
#loginForm{
display:none!important;
}
</style>
';
echo "Welcome, ".$_SESSION['login']."<br><a href='link'>Profile</a>";
}
使用这种方式,您无需转到其他页面进行登录
<?php ob_start(); ?>
<form action="testreg.php" method="post" }>
<p>
<label><span">Username:</span></span><br>
</label>
<input name="login" type="text" size="25" maxlength="15">
</p>
<p>
<label><span class="style3">Password:</span><br>
</labe l>
<input name="password" type="password" class="style3" size="13"
maxlength="15">
</p>
<p><input name="submit" type="submit" value="Enter">
<a href="reg.php" class="style4">Need an account?</</a></p>
</form>
<?php $form = ob_get_clean(); ?>
逻辑到这里
if (empty($_SESSION['login']) or empty($_SESSION['id']))
{
echo $form;
}
else
{
echo "Welcome, ".$_SESSION['login']."<br><a href='link'>Profile</a>";
}