2

我想把登录用户的名字作为页面的标题。但我不知道该怎么做。我尝试了几种方法,但每种方法都显示解析错误。这是我用于登录用户然后显示他的详细信息的 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
                }

            ?>

4

3 回答 3

2

确保您正确标记您的页面:doctype、html-head-body 等。您可以这样做,并且当正文仍然“打开”时,通过简单地从<?php您的脚本开始来声明您的 php 代码。

然后,您的 loginname-as-title 代码的相关部分:

<head>
  <title><?php echo $loginName ?></title><!-- thanks to Berry Langerak for noting 'echo' was missing -->
</head>
<body>
<?php

$loginName您要显示的登录 ID 的 var 当然在哪里。

于 2012-06-14T08:37:50.057 回答
2

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

<title><?php echo htmlspecialchars($myTitle); ?></title>
于 2012-06-14T08:38:10.513 回答
0

使用下面的代码将登录名显示为标题

 echo '<script language="javascript">';
 echo 'document.title = \''.$row['name'].'\'';
 echo '</script>'
于 2012-06-14T08:46:19.120 回答