2014-10-28 2 views
0

하나의 index.php 파일이 있고 대신 something.php, about.php, contact.php 파일이있는 PHP 웹 사이트를 만들고 있습니다. 다음과 같이 설정했습니다. index.php ? P = 뭔가, index.php를 P = 연락 등<head> 태그 뒤에 HTML 메타 데이터

현재 내 index.php를 코드는 다음과 같습니다

<head> 
    <title>Something</title> 
    <link href="theme.css" rel ="stylesheet" media="screen"> 
</head> 

<body> 
<?php 
if (@$_GET['p'] == 'something') include 'pages/something.php'; 
elseif (@$_GET['p'] == 'about') include 'pages/about.php'; 
</body> 

이제 문제는 내가 index.php를 다른 메타 데이터를 갖고 싶어한다는 것입니다 , something.php 및 about.php. <head></head> 사이에 메타 데이터를 추가해야하지만, something.php와 about.php는 나중에 포함됩니다. 파일에 대해 다른 메타 데이터를 사용하려면 어떻게해야합니까? <head></head> 태그 뒤에 메타 데이터를 (다시) 설정할 수 있습니까?

<?php 
if (@$_GET['p'] == 'something') include 'pages/something.php'; 
elseif (@$_GET['p'] == 'about') include 'pages/about.php'; 
?> 

하고 about.php에서의 index.php에서

+1

PHP가 이미 발생했습니다 출력을 수정하기 위해 과거로 도달 할 수 있습니다. 당신은 출력을 버퍼링하여 전혀 보내지 않아야하고 버퍼를 수정하거나 자바 스크립트를 사용하여 클라이언트에 도달하면 ''을 수정하거나 스크립트를 수정하여 여러 단계로 생성해야합니다 페이지를 만들고 적절한 시간/장소에 메타 데이터를 출력합니다. –

답변

1

something.php 전체 HTML 페이지가 내가 모르는 head 태그

1

의 포함을 포함, 당신의 질문을 이해하지만, 않습니다 물론, 헤더에서 if 조건을 사용할 수도 있습니다!

<head> 
    <title>Something</title> 
    <link href="theme.css" rel ="stylesheet" media="screen"> 
    <?php 
     if ($_GET["p"] === 'something') { 
      ?> 
    <!-- Write your metadata here if the page is something... --> 

    <?php 
     } elseif ($_GET["p"] === 'about') { 
     ?> 
    <!-- Write your metadata here if the page is about... --> 
    <?php 
     } 
    ?> 
</head> 

<body> 
    <?php 
    if ($_GET['p'] == 'something') { 
     include 'pages/something.php'; 
    } elseif ($_GET['p'] == 'about') { 
     include 'pages/about.php'; 
    } 
    ?> 
</body> 
1

같은, 기본 설정에 따라 메타 데이터를로드 해보십시오 :

<head> 
    <title>Something</title> 
    <link href="theme.css" rel ="stylesheet" media="screen"> 
    <?php if (@$_GET['p'] == 'something') echo "<meta charset='utf-8'>"; ?> 
</head> 

<body> 
<?php 
if (@$_GET['p'] == 'something') include 'pages/something.php'; 
elseif (@$_GET['p'] == 'about') include 'pages/about.php'; 
?> 
</body> 
관련 문제