dtu15253 2016-03-16 14:29
浏览 68
已采纳

用户登录/注销时显示链接/按钮

I am truly a novice at coding and only succeed with trial and error. I use a WYSIWYG program to do all the main pages in my site and then add php coding to do some specified things.What I am trying to do right now is display a log in button along with a register and forgot password links to those forms, all of which I have built and working, have this display in the masterframe page when a user is not logged in and show another set of user name, profile, logout links when they are logged in. By themselves I have all these functions working, I just cant figure out how to do it this way. Any help or steering me in the right direction to teach me would be great. If you need to be paid for your help that can be arranged as well. Thank You.

update: This is the code that I have right now and use, again I want to have the if else statement show one thing or the other on condition, and have it show in place of, all on the masterframes page.

// have this display if user is logged in

<span id="LoginName1"><?php
if (isset($_SESSION['username']))
{
   echo $_SESSION['username'];
}
else
{
   echo 'Not logged in';
}
?></span>

<div id="wb_Text2" style="">
<span style="color:#FFFFFF;font-family:Tahoma;font-size:12px;"><a href="javascript:displaylightbox('./members/Edit_Profile.php',{width:620,height:710})" target="_self" class="style5">Profile</a></span>
</div>

<form name="logoutform" method="post" action="<?php echo basename(__FILE__); ?>" id="logoutform">
<input type="hidden" name="form_name" value="logoutform">
<a id="Logout2" href="javascript:document.logoutform.submit()">Logout</a>
</form>

//have this display if user is logged out

<a href="javascript:displaylightbox('./members/Log-In.php',{width:490,height:370})" target="_self" id="jQueryButton1" style="width:100%;height:100%;">Log In</a>

<div id="wb_Text3" style="">
<span style="color:#FFFFFF;font-family:Tahoma;font-size:12px;"><a href="javascript:displaylightbox('./members/Create_Account.php',{width:620,height:710})" target="_self" class="style5">Register</a></span>
</div>

<div id="wb_Text1" style="">
<span style="color:#FFFFFF;font-family:Tahoma;font-size:12px;"><a href="javascript:displaylightbox('./members/Forgot_Password.php',{width:350,height:275})" target="_self" class="style5">Forgot Password?</a></span>
</div>

I have tried doing this but I keep getting a syntax error for unexpected '<'

<span id="LoginName1"><?php
if (isset($_SESSION['username']))
{
   echo $_SESSION['username'];

<div id="wb_Text2" style="">
<span style="color:#FFFFFF;font-family:Tahoma;font-size:12px;"><a href="javascript:displaylightbox('./members/Edit_Profile.php',{width:620,height:710})" target="_self" class="style5">Profile</a></span>
</div>

<form name="logoutform" method="post" action="<?php echo basename(__FILE__); ?>" id="logoutform">
<input type="hidden" name="form_name" value="logoutform">
<a id="Logout2" href="javascript:document.logoutform.submit()">Logout</a>
</form>
}
else
{
<a href="javascript:displaylightbox('./members/Log-In.php',{width:490,height:370})" target="_self" id="jQueryButton1" style="width:100%;height:100%;">Log In</a>

<div id="wb_Text3" style="">
<span style="color:#FFFFFF;font-family:Tahoma;font-size:12px;"><a href="javascript:displaylightbox('./members/Create_Account.php',{width:620,height:710})" target="_self" class="style5">Register</a></span>
</div>

<div id="wb_Text1" style="">
<span style="color:#FFFFFF;font-family:Tahoma;font-size:12px;"><a href="javascript:displaylightbox('./members/Forgot_Password.php',{width:350,height:275})" target="_self" class="style5">Forgot Password?</a></span>
</div>
}
?></span>
  • 写回答

5条回答 默认 最新

  • doob0526 2016-03-16 17:16
    关注

    You are mixing both PHP and HTML code. Please correct.

    You have to separate / embed HTML properly in your document while using php conditions.
    Example:

    <?php
    $condition = true;
    if ($condition) {
    ?>
    <h1>This will be displayed when condition is true</h1>
    <?php
    } else {
    ?>
    <h1>This will be displayed when condition is false</h1>
    <?php
    } // else ends
    ?>
    

    Please try this:

    <span id="LoginName1"><?php
    if (isset($_SESSION['username']))
    {
       echo $_SESSION['username'];
    ?>
    <div id="wb_Text2" style="">
    <span style="color:#FFFFFF;font-family:Tahoma;font-size:12px;"><a href="javascript:displaylightbox('./members/Edit_Profile.php',{width:620,height:710})" target="_self" class="style5">Profile</a></span>
    </div>
    
    <form name="logoutform" method="post" action="<?php echo basename(__FILE__); ?>" id="logoutform">
    <input type="hidden" name="form_name" value="logoutform">
    <a id="Logout2" href="javascript:document.logoutform.submit()">Logout</a>
    </form>
    <?php
    }
    else
    {
        ?>
    <a href="javascript:displaylightbox('./members/Log-In.php',{width:490,height:370})" target="_self" id="jQueryButton1" style="width:100%;height:100%;">Log In</a>
    
    <div id="wb_Text3" style="">
    <span style="color:#FFFFFF;font-family:Tahoma;font-size:12px;"><a href="javascript:displaylightbox('./members/Create_Account.php',{width:620,height:710})" target="_self" class="style5">Register</a></span>
    </div>
    
    <div id="wb_Text1" style="">
    <span style="color:#FFFFFF;font-family:Tahoma;font-size:12px;"><a href="javascript:displaylightbox('./members/Forgot_Password.php',{width:350,height:275})" target="_self" class="style5">Forgot Password?</a></span>
    </div>
    <?php
    }
    ?></span>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划