dpjpo746884 2010-10-09 03:13
浏览 33
已采纳

包含基于点击链接的文件

I am beginning to develop a website as a personal project, to discover a little bit web technologies. My question is more about "how to make the things clean" than a technical question.

Here is the thing:

Let's say that an index.php page will include an other menu.php, which will permit to navigate the website.

My index.php look like this, basically:

include("header");
include("menu");
include("DEPENDING ON WHICH LINK AS BEEN CLICKED FROM THE MENU");
include("bottom");

To avoid the POST method, and have a lot of stuff on my URL, I would like to do it an other way, but I do not know what is the best one.

I thought about declaring a variable like $page, when a link is clicked, I can do something like "if $page == home", then I include the home.php page... etc...

I do not know if my question is clear... I know that it will appear as a very easy and beginner question but I don't even know where to look...

Do you know if I can find any "open source website" so I can study the code and see the best practices about it?

P.S.: Sorry for my english which is probably not perfect at all, I am working on it.

  • 写回答

4条回答 默认 最新

  • duanming0494 2010-10-09 03:24
    关注

    You can have a menu like

    <a href="?view=home">Home</a>
    <a href="?view=home">About</a>
    

    Then on your PHP code

    include $_GET["view"] . ".php";
    

    Note that I am not validating, so any parameter passed on the url would be able to include any file.

    The $_GET returns the values passed to the page through the URL.

    The $_POST returns values posted.

    The $_REQUEST returns both $_GET and $_POST values.

    A good place to study many languages is W3Schools, you could check there sometime.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c