我想从下面的链接中获取ID。它可以跳过页面路由,但我需要使用页面路由并打破$_GET['id']
。有没有办法让我使用页面路由,或者我应该看看另一个解决方案?
on HOME.PHP 我写这个:
<h1 class="post-title"><a href="viewlink?id=<?php echo $row['postID'] ?>"><?php echo $row['postTitle'] ?></a></h1>
我从根目录路由所有页面,似乎没有给我
viewlink.php
echo $_GET['id'];
这就是我的页面路线
if (isset($_GET['page'])) {
$page = $_GET['page'];
if ($page == "index") {
require_once "frontend/pages/index.php";
} elseif ($page == "viewlink") {
require_once "frontend/pages/viewlink.php";
}
}
答案 0 :(得分:0)
您没有显示如何路由,因此无法告诉您如何获得基本page
密钥。如果你做一些标准的重写方法,你可能会留下类似于此的$_SERVER
数组。这些值中的任何一个都可能是您提取id
,QUERY_STRING
,REQUEST_URI
或REDIRECT_QUERY_STRING
等所需的内容:
Array
(
[DOCUMENT_ROOT] => /var/http/htdocs/iwantcreative
[DOMAIN_NAME] => www.example.com
[DOMAIN_NAME_REAL] => example.com
[DOMAIN_PATH] => /var/http/htdocs/iwantcreative
[DOMAIN_USER] => 2948313.3268049
[FCGI_ROLE] => RESPONDER
[GATEWAY_INTERFACE] => CGI/1.1
[HTTP_ACCEPT_LANGUAGE] => en-us
[HTTP_CONNECTION] => close
[HTTP_COOKIE] => PHPSESSID=123123123123123123aaaaabbbbccccc
[HTTP_DNT] => 1
[HTTP_HOST] => www.example.com
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS 7_6_2) AppleWebKit/604.4.7 (KHTML, like Gecko) Version/11.0.2 Safari/604.4.7
[HTTP_X_FORWARDED_FOR] => 123.123.123.1
[HTTP_X_FORWARDED_PROTO] => http
[HTTP_X_REAL_IP] => 111.111.111.1
[PHP_SELF] => /index.php
[PHP_WRAPPER_VERSION] => 560
[PKEY] => 123123123.321321321
[QUERY_STRING] => viewlink/&id=100
[RAILS_URI] => INVAL
[REDIRECT_DOMAIN_NAME] => www.example.com
[REDIRECT_DOMAIN_NAME_REAL] => example.com
[REDIRECT_DOMAIN_PATH] => /var/http/htdocs/myrootfolder
[REDIRECT_PKEY] => 123123123.321321321
[REDIRECT_QUERY_STRING] => viewlink/&id=100
[REDIRECT_RAILS_URI] => INVAL
[REDIRECT_SCRIPT_URI] => http://www.example.com/viewlink/
[REDIRECT_SCRIPT_URL] => /viewlink/
[REDIRECT_STATUS] => 200
[REDIRECT_URL] => /viewlink/
[REMOTE_ADDR] => 111.111.111.1
[REMOTE_PORT] => 57480
[REQUEST_METHOD] => GET
[REQUEST_TIME] => 1515127759
[REQUEST_TIME_FLOAT] => 1515127759.7582
[REQUEST_URI] => /viewlink/&id=100
[SCRIPT_FILENAME] => /var/http/htdocs/myrootfolder/index.php
[SCRIPT_NAME] => /index.php
[SCRIPT_URI] => http://www.example.com/viewlink/
[SCRIPT_URL] => /viewlink/
[SERVER_ADDR] => 123.123.123.1
[SERVER_ADMIN] => [no address given]
[SERVER_NAME] => www.example.com
[SERVER_PORT] => 80
[SERVER_PROTOCOL] => HTTP/1.0
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache
[argc] => 1
[argv] => Array
(
[0] => viewlink/&id=100
)
答案 1 :(得分:0)
看来你也有某种网址重写设置,你没有提到。通常这个链接:<a href="viewlink?...
可能会导致404,因为它缺少.php扩展名。
你如何从<a href="viewlink?...
到达路由部分?我猜你有一个错误 - 检查RewriteRule(apache),他们需要[QSA]
- &#34;查询字符串追加&#34;在行尾。查询字符串是&#34;?&#34;之后的任何内容在网址中,您的情况为?id=