php - 网页标题 用户名

标签 php sql title

我想将登录用户的名称作为页面的标题。但我不知道该怎么做。我尝试了多种方法,但每种方法都显示解析错误。这是我的 php 代码,用于登录用户并显示他的详细信息。

<?php

                //if the login session does not exist therefore meaning the user is not logged in
                if(strcmp($_SESSION['uid'],"") == 0){
                    //display and error message
                    echo "<center>You need to be logged in to user this feature!</center>";
                }else{
                    //otherwise continue the page

                    //this is out update script which should be used in each page to update the users online time
                    $time = date('U')+50;
                    $update = mysql_query("UPDATE `employer` SET `online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'");
                    $display_query = mysql_query("SELECT * FROM employer WHERE `id` = '".$_SESSION['uid']."'");
                    echo "<table id='pageTable'><tbody><th>Your Details</th>";
                    echo "<tbody>";
                    while($row = mysql_fetch_array($display_query)){
                        echo "<tr><td>Name&#58;&nbsp;</td><td>".$row['name']."</td><tr>";
                        $titlename = $row['name'];
                        echo "<tr><td>E&#45;Mail ID&#58;&nbsp;</td><td>".$row['email']."</td><tr>";
                        echo "<tr><td>Contact No&#46;&#58;&nbsp;</td><td>".$row['contact']."</td><tr>";
                        echo "<tr><td>Company&#58;&nbsp;</td><td>".$row['company']."</td><tr>";
                        echo "<tr><td>Designation&#58;&nbsp;</td><td>".$row['designation']."</td><tr>";
                    }

                    echo "</tbody>";
                    echo "</table>";
                    echo "<table><tr><td>";
                    echo '<div class="button"><a href="functions/logout.php">Logout</a></td></tr></table>';


                //make sure you close the check if they are online
                }

            ?>

最佳答案

在输出 <head> 之前你需要先获取你想要的数据页面部分,然后包含 <title> 其中的元素。

<title><?php echo htmlspecialchars($myTitle); ?></title>

关于php - 网页标题 用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11029357/

相关文章:

mysql LIKE 查询耗时太长

jquery - 替换元素标题框?

php - 如何检查未选择任何查询?

php mysql 和 in_array 性能

php - 当用户在选择字段中选择新选项时,如何运行 mysql 查询?

jquery - 我想从图像中获取标题属性并将其添加到周围的链接

wordpress - 如何更改 Google 对网站名称的显示

php - 在 PHP 中获取解析错误 : syntax error, 意外的 $end

MySQL 外键约束的形成不正确

MySQL - 如何存储 GROUP BY 的结果以便在重复键更新中使用