doujia7162 2013-07-31 18:17
浏览 21
已采纳

PHP - 登录后重定向到上一页并包含获取数据

Okay so first off, sorry if this is a duplicate. I've searched for around 20 minutes all over stack overflow AND the internet, and I can't seem to find a solution to my problem.

What I'm trying to do:

I have a login form on every page, with a hidden input containing the current page the user is on - so when they login, it successfully redirects back to the page they were on.

E.g. User is on news.php and not logged in. They login, which takes them to login.php to verify data, then redirects back to news.php

This works great!

The problem: If there is any get data or anchor tags at the end of the URL, I can't seem to redirect back to that.

E.g. User is on news.php?id=4#comments and not logged in. They login, etc etc, but it redirects back to news.php and ignores the trailing data.

Anyone have any help here?

My code:

<input type="hidden" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" name="location"  />

$previousPage = $_POST['location'];
header("refresh: 1; url=".$previousPage);

Obviously I think the issue is the $_SERVER['HTTP_REFERER'] part, but I'm not sure what to replace it with to make it include trailing data.

All help is appreciated!

  • 写回答

2条回答 默认 最新

  • dongzhenjian5195 2013-07-31 18:20
    关注

    Just use

    print_r($_SERVER);

    and select the one that fits your needs most!

    Hint: Combine HTTP_HOST and REQUEST_URI.

    The hash portion will actually never be send to the server: Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 机器学习简单问题解决
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写