dqqxkq4047 2016-11-24 13:09
浏览 30

index.php无法正常工作?

So I need to put together simple website using php- header and footer will be the same and the middle section changes. I need to be able to click on the link in header and change the section (hem or nyheter, hem is the default). What may be the reasons the following code does not work once I click on link in the header? It loads correctly the first time, but once I click on the link, the header and footer does not load, only the section part opens in a browser. I have htaccess file and header, footer and sections files are on the same level.

Thanks in advance!

<?php

$sections = array("hem", "nyheter");
$sectionTitles = array("HEM", "NYHETER");

$section = "hem";

$content = explode("/", $_SERVER['REQUEST_URI']);

if (!empty($content[2]) && (in_array($content[2], $sections))) { $section = $content[2];}

include ("header.php");
include ("$section.php");
include ("footer.php");

?>

Header code:

<body>
    <a href="hem">hem</a> | <a href="nyheter">nyheter</a>

.htaccess:

 RewriteEngine On
 RewriteCond %{REQUEST_URI} !\.(php|css|js|gif|png|jpe?g|pdf|eot|svg|ttf|woff|ico)$
 RewriteRule (.*)$ index.php [L]
  • 写回答

1条回答 默认 最新

  • doulan8152 2016-11-24 13:12
    关注

    I tried using the site url that i have added please try with is, it worked for me and change your code according to you

        <?php
    
    $sections = array("hem", "nyheter");
    $sectionTitles = array("HEM", "NYHETER");
    
    $section = "hem";
    
    $sitefolder = "/krist";
    $site_url   = "http://".$_SERVER["HTTP_HOST"].$sitefolder.'/index.php';
    
    $content = explode("/", $_SERVER['REQUEST_URI']);
    
    if (!empty($content[2]) && (in_array($content[2], $sections))) { $section = $content[2];}
    
    include ("header.php");
    include ($section.".php");
    include ("footer.php");
    
    ?>
    

    Header code:

    <body>
    <a href="<?php echo $site_url.'/hem'?>">hem</a> | <a href="nyheter">nyheter</a>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog