简体   繁体   中英

index.php not working properly?

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]

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM