网页的Php标题


Php title for web page

我的header.php上有这段代码。它用于动态创建标题。问题是,当用户在article.php(阅读文章的页面)上时,它只会创建一个标题,但在其他页面上会产生"未定义变量i"错误。我应该更改什么,或者谁知道网页标题的更好代码?我是id。

   if(isset($i=$_GET['i']) && $i = true ) {  
$i=$_GET['i'];
$tbl_name="yote";
$sql=mysql_query("SELECT * FROM $tbl_name WHERE i='$i'") or die(mysql_error());
while($rows=mysql_fetch_array($sql)){
$title = $rows['title']. "";
}
mysql_close();   
   } else { 
         $title = 'Malloooo - News, Reviews, Analysis and Market Watch From Around The World';     
                 } 
?>
<!-- Header
================================================== -->
<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
<head>
<!-- Basic Page Needs
 ================================================== -->
<meta charset="utf-8">
<title><?php echo $title; ?></title>

老实说,您的代码有很多错误。

  1. if (isset($i=$_GET['i']) ...:不确定你想用它做什么,但它是无效的
  2. ... && $i = true):这是在设置一个值,而不是检查它
  3. 您极易受到SQL注入的攻击。查看PDO:http://php.net/PDO