php $ _SERVER ['PHP_SELF']包含查询字符串 [英] php $_SERVER['PHP_SELF'] to include query string

查看:69
本文介绍了php $ _SERVER ['PHP_SELF']包含查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实质上是在尝试创建一个登录系统,该系统将使用户返回到他们所在的页面.我知道这个问题已经问了一点,我已经看过SO的其他答案,但是我找不到解决我特定问题的方法.

I'm essentially trying to make a login system that will return the user back to the page they were on. I know this question has been asked a bit, and I've looked at the other answers on SO, but I cannot find a solution to my particular problem.

我的网站上有一个带有参考ID号的表格(例如:10001、10003、10004,... 53401等).这些数字也是链接.所有链接都指向一页("mypage.php"),并且参考ID号(10004)成为该URL的查询字符串:

My site has has a table with reference id numbers (ex: 10001, 10003, 10004, ... 53401, etc.). These numbers are also links. All links point to one page ("mypage.php"), and the reference id number (10004) becomes a query string to that url:

<td><?php echo '<a href="mypage.php?query_ecr=', urlencode($num), '">'; ?><?php echo $num; ?></a></td>

在网站的每个页面上的"header.php"上,菜单上都有一个按钮,它将打开下面的表单供用户登录.

On my "header.php", which is on every page of the site, there is a button on the menu that will open the form below for the user to log in.

<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"的隐藏输入".我想捕获用户所在的当前页面.我已经有一个登录脚本,该脚本将检查用户名和密码并将其重定向到所需的页面.

Notice the "hidden input" with the name='redirurl'. I want to capture the current page the user is on. I already have a login script that will check the username and password and redirect them to the page they need to be.

//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.....
              }

我的问题是,如果客人单击链接(例如:10004),则会将其带到网址:

My problem is that if the GUEST clicks on a link (ex: 10004), they are taken to the url:

http://www.XXXXXX.XXXX/mypage.php?query_ecr='10004'

但是,在该页面上,"redirurl"的值是:

However, on that page the value for 'redirurl' is:

http://www.XXXXXX.XXXX/mypage.php

它忽略查询字符串.因此,当用户从该页面登录时,我的登录脚本将其重定向回该页面时,该页面存在大量错误,因为它需要查询字符串.

It disregards the query string. So when the user logs in from that page, and my login script re-directs them back to that page, the page has a ton of errors because it needs the query string.

如何在$ _SERVER ['PHP_SELF']中包含查询字符串?

How do I include the query string in: $_SERVER['PHP_SELF'] ?

推荐答案

您可以使用:

$_SERVER['REQUEST_URI']

获取域名文件夹,查询字符串等之后的所有内容. 然后,您可以使用其他$ _SERVER变量添加域,或者如果不更改主机,也可以不带域名使用.

to get everything after the domain name folders, query strings etc. You could then either use the other $_SERVER variables to add the domain, or it should be fine to use without a domain name provided you're not changing hosts.

这篇关于php $ _SERVER ['PHP_SELF']包含查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆