如何回应if(isset($ _ SESSION

时间:2018-04-03 21:32:12

标签: php

我试图做这件事。

如果用户未登录,则会显示

https://i.imgur.com/nwiOYYN.png此图片为头像。 +登录ahref

如果用户有会话,则会向他显示Skins行。 + logout ahref。

但是,当我做"否则"它显示了我奇怪的布局。

<?php
    session_start(); //starting session 
    include("config.php"); //including our config.php 
    error_reporting(E_ALL); 


    if(isset($_SESSION['username'])) //if session is set, so if user is logged in... 
    { 
        $username = $_SESSION['username']; //setting variable username as one from session 
        $query = mysql_query("SELECT * FROM users WHERE username = '$username'"); 
        while($row = mysql_fetch_assoc($query)) //looping thousgt table to get informations 
        { 
            $Skin = $row['Skin'];
        }
    } else 
        echo "  <li class='second admin-pic'>
                       <ul class='top_dp_agile'>
                                    <li class='dropdown profile_details_drop'>
                                        <a href='' class='dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>
                                            <div class='profile_img'>   
                                                <span class='prfil-img'><img src='https://i.imgur.com/nwiOYYN.png' alt=''> </span> 
                                            </div>  
                                        </a>
                                        <ul class='dropdown-menu drp-mnu'>
                                            <li> <a href='#'><i class='fa fa-cog'></i> Log IN</a> </li> 
                                            <li> <a href='#'><i class='fa fa-user'</i> Make new Account</a> </li> 
                                        </ul>
                                    </li>

                        </ul>
                </li>";
?>

这是html

<li class="second admin-pic">
                       <ul class="top_dp_agile">
                                    <li class="dropdown profile_details_drop">
                                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                            <div class="profile_img">   
                                                <span class="prfil-img"><img src="images/<?php echo $Skins ?>.jpg" alt=""> </span> 
                                            </div>  
                                        </a>
                                        <ul class="dropdown-menu drp-mnu">
                                            <li> <a href="#"><i class="fa fa-cog"></i> Logout</a> </li> 
                                            <li> <a href="#"><i class="fa fa-user"></i> Forum</a> </li> 
                                        </ul>
                                    </li>

                        </ul>
                </li>

如果是&gt; 1(化身将被命名为数字)以显示html然后而不是那个HTML只是用echo $ skins替换它,我应该定义$ skins吗?

我想要删除HTML并将其替换为echo,例如

    if($Skins    > '0') {
    $Skins = "<li class='second admin-pic'>
                       <ul class='top_dp_agile'>
                                    <li class='dropdown profile_details_drop'>
                                        <a href="#" class='dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>
                                            <div class='profile_img'>   
                                                <span class='prfil-img'><img src='images/<?php echo $Skins ?>.jpg' alt=''> </span> 
                                            </div>  
                                        </a>
                                        <ul class='dropdown-menu drp-mnu'>
                                            <li> <a href=''><i class='fa fa-cog'></i> Logout</a> </li> 
                                            <li> <a href=''><i class='fa fa-user'></i> Forum</a> </li> 
                                        </ul>
                                    </li>

                        </ul>
                </li>";}

和html

// another divs, etc.

?php echo $Skins ?>

new divs

这是好方法吗?因为现在它正好以这种方式显示

https://i.imgur.com/44ipyTw.png

0 个答案:

没有答案