简体   繁体   English

从数据库获取价值到文件夹名称PHP&MYSQL

[英]Getting value from database to a folder name PHP&MYSQL

I am having a problem with a PHP script, so the link is like this: page.php?id=1412 . 我的PHP脚本有问题,因此链接如下: page.php?id=1412

But I don't want to get the data using $_GET['id'] ; 但是我不想使用$_GET['id']获得数据; is there a way for the program to recognize the URL like this localhost/1412 , and then try to find the 1412 in the id field in database? 程序是否有办法识别类似localhost/1412的URL,然后尝试在数据库的id字段中找到1412

If possible how can I avoid the Not Found page ? 如果可能,如何避免Not Found page ? since the folder 1412 does not exist ? 由于文件夹1412不存在?

You could regex the current uri ($_SERVER['REQUEST_URI']). 您可以正则表达式当前uri($ _SERVER ['REQUEST_URI'])。 See for creating regex: PHP URL Regex and Parameter 有关创建正则表达式的信息,请参见: PHP URL正则表达式和参数

.htaccess file is a solution , you can access this type of url and can send the value to php files using .htaccess file refer this nice article for doing this .htaccess文件是一种解决方案 ,您可以访问这种类型的url,并且可以使用.htaccess文件将值发送到php文件,有关此操作,请参见此文章。

http://net.tutsplus.com/tutorials/other/using-htaccess-files-for-pretty-urls/ http://net.tutsplus.com/tutorials/other/using-htaccess-files-for-pretty-urls/

For all of this kind of matching you need to use either .htaccess files for apache, or similar functionality implemented in the configuration files of nginx/lighthttpd and so on. 对于所有此类匹配,您都需要使用.htaccess文件(用于apache)或在nginx / lighthttpd的配置文件中实现的类似功能,等等。 Basicly, when a request like x/1412 will come, you can match it before being dispatched to the php engine and transform it internally into x?id=1412 . 基本上,当x / 1412之类的请求到来时,您可以在将其分配给php引擎之前进行匹配,并将其内部转换为x?id = 1412。 Other solution involves redirecting all requests to a front controller (a script that is serving as a single entry point into the application) and let a url matcher match the route to execute. 其他解决方案包括将所有请求重定向到前端控制器(充当应用程序单个入口点的脚本),并让url匹配器匹配要执行的路由。 The latter is implemented in about every big/small php framework. 后者在几乎每个大/小php框架中都实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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