我实际上是在尝试创建一个登录系统,将用户返回到他们所在的页面。我知道这个问题有点问了,我已经看了SO的其他答案,但我找不到解决我特定问题的方法。
我的网站有一个带参考ID号码的表格(例如:10001,10003,10004,... 53401等)。这些数字也是链接。所有链接都指向一个页面(“mypage.php”),引用ID号(10004)成为该URL的查询字符串:
<td><?php echo '<a href="mypage.php?query_ecr=', urlencode($num), '">'; ?><?php echo $num; ?></a></td>
在网站的每个页面上的“header.php”上,菜单上有一个按钮,打开下面的表单供用户登录。
<form action='login/process.php' method='post'>
<label for='name'>Username:</label>
<input type='text' id='userid' name='user_name'/>
<label for='password'>Password:</label>
<input type='password' name='password' id='userpassword'/>
<input type='submit' value='Log In' />
<input type='hidden' name='login' value='1'>
<input type='hidden' value='".$_SERVER['PHP_SELF']."' name='redirurl'/>
</form>
注意名称为'redirurl'的“隐藏输入”。我想捕获用户所在的当前页面。我已经有了一个登录脚本,它将检查用户名和密码,并将它们重定向到他们需要的页面。
//login/process.php
...blah blah blah other stuff...
global $database,$session;
$this->user_status=$database->CheckUserPass($_POST['user_name'],$_POST['password']);
$url = $_POST['redirurl'];
if($this->user_status==1)
{
$session->StartSession($_POST['user_name'],$_POST['password']);
header("Location: ".$url);
} else {
...blah blah blah.....
}
我的问题是,如果GUEST点击链接(例如:10004),他们会被带到网址:
http://www.XXXXXX.XXXX/mypage.php?query_ecr='10004'
但是,在该页面上,'redirurl'的值为:
http://www.XXXXXX.XXXX/mypage.php
忽略查询字符串。因此,当用户从该页面登录,并且我的登录脚本将它们重定向回该页面时,该页面有大量错误,因为它需要查询字符串。
如何将查询字符串包含在:$ _SERVER ['PHP_SELF']中?
答案 0 :(得分:7)
您可以使用:
$_SERVER['REQUEST_URI']
获取域名文件夹,查询字符串等后的所有内容 然后,您可以使用其他$ _SERVER变量来添加域,或者如果您没有更改主机,则可以在没有域名的情况下使用。
答案 1 :(得分:6)
怎么样:
echo $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
请注意,您可能希望像这样清理输出:
$url = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
echo htmlspecialchars($url, ENT_QUOTES, 'utf-8');
防范XSS。
答案 2 :(得分:1)
查询字符串在$_SERVER['QUERY_STRING']
中可用。只是将它们连接起来(不要忘记问号),你就没事了。 :)
答案 3 :(得分:0)
如果您仍然在寻找答案,那就在这里。
假设这是您的网址:
Right
这是选项。第一个返回域之后的所有内容,第二个返回当前页面及其查询。
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
class Mainwindow(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("window")
self.lineEdit = QtWidgets.QLineEdit()
self.lineEdit_2 = QtWidgets.QLineEdit()
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.lineEdit)
self.layout.addWidget(self.lineEdit_2)
self.setLayout(self.layout)
regexp = QtCore.QRegExp("^\\d+[\.,]\\d+$|^\\d+$") #accepts numbers in format 111.111 or 111,111 or 111
validator = QtGui.QRegExpValidator(regexp)
self.lineEdit.setValidator(validator)
self.lineEdit.returnPressed.connect(lambda: print(self.lineEdit.text()))
if __name__ == '__main__':
app = QtWidgets.QApplication([])
application = Mainwindow()
application.show()
sys.exit(app.exec())