当URL传递变量时,php $ _g是空的
这是我的第一个堆栈溢出问题。 我有一个主页,您可以在其中登录,如果您登录它会将您发送到登录php,其中有一些代码检查登录是否不正确。如果是这种情况,则此代码将您重定向到主页:
标题(“位置:” .Server_Address。“ Home?error = Invalid_login”);
现在您回到主页,但是url url未设置变量。它没有在 var_dump(parse_url($ _ server ['http_referer'])));
or var_dump($ _ get);
这是我的index.php文件:
<?php
session_start();
require_once("config.php");
if(!(isset($_GET['page']))) { // redirect to main page
header("Location: ".SERVER_ADDRESS."home");
} else {
$mp = new MainPage($_GET['page']); // redirect to given page
}
?>
如果您尝试使用错误的凭据再次登录,并且执行相同的重定向过程,则现在将显示变量。 如果我要在几秒钟后刷新标头,也会发生同样的事情。
我似乎不明白为什么主页不会立即显示变量,我只想将变量用于IF语句,该语句会打印出额外的无效登录消息。
我正在使用wampserver64进行局部主机。
我的.htaccess
看起来像这样:
Options FollowSymLinks
RewriteEngine On
RewriteRule ^([0-9a-zA-Z\-\#]+)/?$ index.php?page=$1 [L]
编辑: cbroe的答案对我有帮助,我的htaccess没有QSA标志
this is my first stack overflow question.
I have a home page, where you can login, if you login it sends you to a login php in which you have some code that checks if login is incorrect. If that is the case this code redirects you back to home page:
header("Location: ".SERVER_ADDRESS."home?error=invalid_login");
Now you are back on the home page but the url variable is not set. It does not show in avar_dump(parse_url($_SERVER['HTTP_REFERER']));
orvar_dump($_GET);
This is my index.php file:
<?php
session_start();
require_once("config.php");
if(!(isset($_GET['page']))) { // redirect to main page
header("Location: ".SERVER_ADDRESS."home");
} else {
$mp = new MainPage($_GET['page']); // redirect to given page
}
?>
If you go try login again with wrong credentials and do the same redirection process it will now show the variable.
Same thing happens if I were to refresh the header after few seconds.
I seem to not understand why the home page would not show the variable straight away, I just want to use the variable for an if statement that would print an extra invalid login message.
I am using wampserver64 for localhosting.
My .htaccess
looks like this:
Options FollowSymLinks
RewriteEngine On
RewriteRule ^([0-9a-zA-Z\-\#]+)/?$ index.php?page=$1 [L]
EDIT:
CBroe's answer helped me, my htaccess did not have a QSA flag
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的规则与
home
匹配,并将请求重写为/index.php?page=home
。您需要添加
QSA
标志 - 查询字符串附加 - 以获得您在此处创建的新查询字符串,并将其与任何现有查询字符串合并。Your rule matches on
home
, and rewrites the request to/index.php?page=home
.You need to add the
QSA
flag - query string append - to get the new query string you are creating there, merged with any existing one.