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 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题