【发布时间】:2011-02-18 14:07:58
【问题描述】:
我从 mysql 数据库中获得了一些基本结果并将其列在一个页面上,在该页面上我添加了带有变量 user_id 的链接:
href=\"http://localhost/TESTING/template.php?user_id=$user_id\" >click here
在 template.php 文件中,我将获取 $user_id 并显示相关的完整数据。
问题是我不希望 user_id=249 http://localhost/TESTING/template.php?**user_id=**249 显示在我想要“http://localhost/TESTING/template.php/249”之类的网址中。
我已经研究了几天没有成功,这可能吗?或者模板文件是否需要显示 user_id=$user_id 才能获取变量?
======================
更新:我添加了代码
重写引擎开启
RewriteBase /TESTING/
RewriteRule ^template.php/([0-9]+)(/)?$ template.php?user_id=$1 [L]
将链接变量更改为 href="localhost/TESTING/template.php/{$user_id}" >点击这里
重写现在有效,但我没有得到 $user_id = $_GET["user_id"]; 的变量在 template.php 页面上
我将以下内容添加到 template.php 页面以查看通过 url 传递的内容:
<?php
ini_set('display_errors',1);
echo '<b>$_GET Variables</b><pre>';
var_dump( $_GET );
echo '</pre>';
?>
并得到以下响应:
$_GET 变量
数组(1){ ["user_id"]=> 字符串(2)“21” }
如何获取变量?
============
现在更新有效!链接中的 {$user_id} 不是 {user_id} - 我可以发誓我尝试了两种方式。
【问题讨论】:
-
也让我们知道什么服务器/设置,即 windows/unix
标签: php mod-rewrite query-string