Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无var的php查询=_Php_Html_Http Status Code 404 - Fatal编程技术网

无var的php查询=

无var的php查询=,php,html,http-status-code-404,Php,Html,Http Status Code 404,我希望我的网站的最终用户能够按照以下方式做一些事情:example.com/user/user\u name在不同的网站上显示该用户的统计信息。简而言之,我希望能够在php中进行查询,而无需用户执行以下操作:example.com/user/username=user\u name我也无法了解所有可能的用户。我想这意味着我希望总是重定向到索引,同时保留其中没有“var=”的querystring。我该怎么做呢?您可以在php中使用explode函数。在url斜杠“/”上使用它,您将获得要查询的有

我希望我的网站的最终用户能够按照以下方式做一些事情:
example.com/user/user\u name
在不同的网站上显示该用户的统计信息。简而言之,我希望能够在php中进行查询,而无需用户执行以下操作:
example.com/user/username=user\u name
我也无法了解所有可能的用户。我想这意味着我希望总是重定向到索引,同时保留其中没有“var=”的querystring。我该怎么做呢?

您可以在php中使用explode函数。在url斜杠“/”上使用它,您将获得要查询的有效数据。记住要确保sql注入的安全性

编辑 给你:

$url = explode('/',$_SERVER['REQUEST_URI']);
echo 'user = '.$url[count($url)-1].'<br />
username = '.$url[count($url)-2];
然后,如果您不想让某个文件夹进入index.php,请在该文件夹中添加一个htaccess文件,其中包含:

RewriteEngine Off

最简单的方法是将脚本保持为
somepage.php?username=user\u name
,然后在
.httaccess
文件中:

RewriteEngine On
RewriteRule ^/user/(.*) somepage.php?username=$1

这样,您仍然可以使用
$\u get['username']
获取变量,但对用户来说它看起来很不错。

我理解这一点。我只是不知道如果没有每个可能的用户名的目录怎么做。我想我的问题是,如何始终重定向到index.php并保留用户的查询?谢谢!这正是我要找的!(编辑3是我使用的)好吧,你的建议确实有效,但我最终将其改为
RedirectMatch^/id/(.*)/index.php?id=$1
RewriteEngine On
RewriteRule ^/user/(.*) somepage.php?username=$1