gpt4 book ai didi

php - 使用 PHP 的动态导航包括

转载 作者:行者123 更新时间:2023-12-04 18:03:24 25 4
gpt4 key购买 nike

我对如何动态更改网页中显示的内容有疑问。我修复了网站的几个部分 - 页眉、导航、页脚、启动画面和侧边栏。

我只希望我网站的中间部分根据用户点击的菜单链接进行更改。

下面是我的 index.php 代码

<?php
include "/templates/header.php";
include "templates/menu.php";
include "/templates/splash.php";
$action = "index";
$disallowed_paths = array('header','menu','splash','bottom_page', 'footer');
if (!empty($_GET['action']))
{
$tmp_action = basename($_GET['action']);
if (!in_array($tmp_action, $disallowed_paths) && file_exists("/content/$tmp_action.php"))
$action = $tmp_action;
}
include "/content/$action.php";
include "/templates/bottom_page.php";
include "/templates/footer.php";
?>

我的menu.php 包含主页关于产品服务 登录链接我只想将 ma​​in_index.php 更改为 include以上基于用户点击的内容。

请告知这种方法是否好。或者我应该根据在菜单上单击的链接多次创建与 index.php 类似的文件并包含到每个文件

最佳答案

你的答案是

GET method

您可以为此使用get 方法

 <ul>
<li><a href="?page=example_1">example 1</a></li>
<li><a href="?page=example_2">example 2</a></li>
<li><a href="?page=example_3">example 3</a></li>
<li><a href="?page=example_4">example 4</a></li>
</ul>

After User Clicks on the link

<?php
if(isset($_GET['page']) && $_GET['page']!=""){
$page = "";
switch ($_GET['page']) {
case 'example_1':
$page = "Page_1.php";
break;

case 'example_2':
$page = "Page_2.php";
break;

case 'example_3':
$page = "Page_3.php";
break;

case 'example_4':
$page = "Page_4.php";
break;

default:
$page = "any_default_page.php";
break;
}

include($page);
}
?>

还有其他方法。但这是最简单高效的

关于php - 使用 PHP 的动态导航包括,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31341637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com