douzai2562 2010-08-11 13:57
浏览 24

重定向正常工作的问题php

I have a little problem with redirecting. Registered users follows this link site.com/reg.php?passkey=1234 but the first the user get redirected to the correct language based on a cookie. I need to keep the passkey variable when the user is redirected. like this ?lang=en_US&passkey=1234

My code so far look something like this:

if (!isset($_GET['lang']))
{

        if (isset($_COOKIE['country'])) 
        {

                $country = $_COOKIE['country'];

                (...)

                elseif  ( $country == "US" ){       

                $variables = $_GET;
                $variables['lang'] = "en_US";

                header('Location: ?' . http_build_query($variables));

                exit();
                }   

This works:

reg.php
reg.php?lang=en_US
reg.php?lang=en_US&passkey=test
reg.php?passkey=test&lang=en_US

but this gives an The page isn't redirecting properly error

reg.php?passkey=test

I don't understand why this doesn't work when all the other combinations seem to work perfectly.

  • 写回答

2条回答 默认 最新

  • doufen3091 2010-08-11 14:21
    关注

    The HTTP 1.1 Specification requires that the location needs to be a Absolute URI (See RFC2616 14.30 Location)

    The location header('Location: ?' . http_build_query($variables)); does not contain an absolute URI.

    You need something like:

    header('Location: /folder/file.php?'.http_build_query($variables));
    

    If you need to do this on different locantions you can use $_SERVER['PHP_SELF'] to set the current file as redirect location. For example

    header('Location: '.$_SERVER['PHP_SELF'].'?'.http_build_query($variables));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题