如何包括与$ _GET功能和安培的页面; htaccess的链接? [英] How to include page with $_GET function & htaccess linking?

查看:171
本文介绍了如何包括与$ _GET功能和安培的页面; htaccess的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前开发一个网站,并想知道如何使用包含在$ _Get功能页面进入主索引(只改变一个特定领域的内容,而不是整个页面)。

文件将类似的index.php(其中的内容页面都包含),news.php(索引默认页面显示),members.php,about.php,guides.php,downloads.php,sponsors.php等

我相信,(如果我没记错的话)与$ _Get方法连接通常看起来像这样的index.php?PID =约

我也想看看我怎么可以更改链接链接如下(通过htaccess的?):mywebsite.com/index.php?pid=about

这已经有一段时间,因为我做了任何PHP和不记得上面的事情究竟怎么做的。

我所工作的

preVIEW可以在 www.survivaloperations.net/dev/ <被发现/ A>

解决方案

您会把所有文件在一个页面的文件夹,只需reugular .php文件。

您的index.php应该是这样的:

 包括:(页/$ _GET ['的pid].PHP);
 

和让你的文件看起来像:

 页/ home.php
页/ contact.php
 

,你会去:

 的index.php?PID =家庭
的index.php?PID =接触
 

分别为

您也想拥有控制哪些$ _ GET值是允许的。我建议使用PHP的开关:

 开关($ _ GET ['PID']){
      案家:包括:(home.php);打破;
      案联系:包括:(contact.php);打破;
      案事:包括:(thing.php);打破;
      默认:包括(404.php);打破;
 }
 

的开关需要更少的code比一堆else if语句,并允许一个默认无效PID被输入时要显示的404型的页面。这也保证了用户访问任何他们不应该......像../db.php什么的(不知道是否父目录的访问是可能的,但仍然)。

Currently developing a website and am wondering how to include pages into the main index (to only change a certain areas content and not the whole page) using the $_Get function.

Files would be something like index.php (where content pages are included), news.php (default page display on index), members.php, about.php, guides.php, downloads.php, sponsors.php etc.

I believe (if i remember correctly) linking with the $_Get method usually looks something like this index.php?pid=about

I would also like to find out how I can change the link (via htaccess?) to link as follows: www.mywebsite.com/about/ instead of mywebsite.com/index.php?pid=about

It has been some time since I have done any PHP and do not remember how the above things are done exactly.

Preview of what I am working on can be found at www.survivaloperations.net/dev/

解决方案

You would put all of your files in a pages folder, just reugular .php files.

your index.php would look like this:

include('pages/'. $_GET['pid']. '.php');

And so your files would look like:

pages/home.php
pages/contact.php

and you would go to:

index.php?pid=home
index.php?pid=contact

respectively

You would also want to have control over which $_GET values are allowed. I reccomend using a php switch:

 switch($_GET['pid']) {
      case "home": include("home.php"); break;
      case "contact": include("contact.php"); break;
      case "thing": include("thing.php"); break;
      default: include("404.php"); break;
 }

The switch requires less code than a bunch of else if statements, and allows for a default "404"-type page to be displayed when an invalid pid is entered. It also secures users from accessing anything they shouldn't... like "../db.php" or something (not sure if parent directory access is possible, but still).

这篇关于如何包括与$ _GET功能和安培的页面; htaccess的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆